Becareful when using this function to check errors, as it seems to read from a buffer of errors, which could include errors from another script or process that was using openssl functions. (I was surprised to find it returing error messages before I had called any openssl_* functions)
To clear the errors, you can do:
while ($err = openssl_error_string());
before using openssl functions. I'm not totally sure of the effect this will have on other threads though, maybe someone can clairify.