I think the answer you are looking for lies in the PHP documentation in user comments:
openssl_verify () - user comment
This should help you. And remember that while you can get the certificate file, you can use cURL () to extract this instead of fread if that (or, at least theoretically, you should be able to).