Recently found file in project_get_Contents, fopen suddenly doesn’t work?
After troubleshooting, it is found that the access can be successful by using HTTP access, and an error will be reported with s and false will be returned;
At first, I thought it was an SSL certificate problem, so I changed the certificate and operated again; False is returned. Detailed error log: SSL routes: ssl3_get_server_certificate:certificate verify failed;
Still not;
file_get_Contents can be solved in the following three ways:
1. Modify the php.ini configuration file
For PHP under windows, just go to php.ini and delete the front of extension=php_openssl.dll; and restart the service. (Note that allow_url_fopen must also be turned on)
For PHP under Linux, you must install the OpenSSL module. After installation, you can access it.
2.stream_context_Create method
$url= 'https://example.com'; $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); $response = file_get_contents($url, false, stream_context_create($arrContextOptions));
3. Replace file with curl function_ get_ contents
function getSslPage($url) { /* http://www.manongjc.com/article/1428.html */ $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); curl_close($ch); return $result; }
Use method 2 to solve the file_get_contents problem temporarily, but I always feel something is wrong, because it can be accessed before;
Later, fopen reported an error of false;
Keep looking for information……
This is because PHP cannot verify the certificate. Look at phpinfo and find openssl.cafile, which can be found in the php.ini file;
The certificate exists. It should be expired. Replace the certificate.
You can download the latest CA certificate at the following address
https://curl.haxx.se/ca/cacert.pem
Replace the certificate and reload the PHP configuration; Perfect solution!!!
Similar Posts:
- failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
- PHP Curl: How to Sending Post JSON Formate Data
- failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
- Error 77 when solving PHP curl HTTPS
- Send QQ e-mail message prompt: error in certificate certificate is not trusted
- [Solved] Composer Install Error: PHP Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages:
- Curl https Error: curl: (60) Peer certificate cannot be authenticated with known CA certificates
- Nltk’s word splitter Punkt: SSL problem, unable to download
- Unable to open thread: http request failed! (4 pesos, PHP 4)
- file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request