I'm using the Google Recaptcha library (https://github.com/google/recaptcha) to confirm form submissions. This has been working fine for months. Suddenly I started noticing a lot of errors like:
ErrorException: file_get_contents(): Failed to enable crypto in /vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php:68
(called from \ReCaptcha\ReCaptcha::verify) This exception can be replicated intermittently with a simple request (outside the library):
file_get_contents('https://www.google.com/recaptcha/api/siteverify');
When it errors, it takes about 52 seconds to time out before displaying the error, otherwise it succeeds right away. No idea where this timeout value is coming from. Older posts have suggested that this error is related to SSL3 (it's not--obviously Google is not using it, it uses TLS 1.2). I've also tried using the latest cacerts.pem file (from curl), but the problem persists.
I also have no problem pulling that URL with curl (from PHP or cli).
The server is running PHP 7.1.3 on Ubuntu 14.04. I do not experience this issue on my local machine, running the same PHP on Ubuntu 16.10, so I'm wondering if that could somehow be related. I'm really at a loss here. I know I can fork the library and rewrite it to use curl instead of file_get_contents, but that seems like a work-around at best.