According to php.net, "file_get_contents() is the preferred way to read the contents of a file into a string." When using this method to read from a URL in your PHP application, you might encounter timeouts intermittently depending on the remote server.
Here is what the error might look like:
PHP Warning: file_get_contents(): SSL: Handshake timed out in /home/user/public_html/script.php on line 2
PHP Warning: file_get_contents(): Failed to enable crypto in /home/user/public_html/script.php on line 2
PHP Warning: file_get_contents(https://domain.tld/test.txt): failed to open stream: operation failed in /home/user/public_html/script.php on line 2
One cause of the error is that the network, server, or CDN where the domain you are requesting has a latency issue, or your requests are rate-limited.
You can check for this by checking the time that it takes to load the contents of the URL from SSH on your server:
# time curl -v https://domain.tld/test.txt ; echo
* About to connect() to domain.tld port 443 (#0)
* Trying 127.0.0.1...
* Connected to domain.tld (127.0.0.1) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
< HTTP/1.1 200 OK
* Connection #0 to host domain.tld left intact
As you can see, if it takes a long time to connect to the remote website, this can cause a timeout. The owner of the remote domain should investigate the timeout. If the domain is behind a Content Delivery Network, try disabling it so that the requests are sent directly to the correct server.