Symptom: php curl calls https error
Troubleshooting method: Try using curl call in the command line.
Cause: The computer room where the server is located cannot verify the SSL certificate.
Solution: Skip SSL certificate check.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Symptoms: php curl calls curl_exec to return bool (false), and the command line curl call is normal.
Troubleshooting method:
var_dump(curl_error($ch));
Check the return value of initialization and execution of cURL function.curl_error()
andcurl_errno()
will return further information in case of failure:
try { $ch = curl_init(); if (FALSE === $ch) throw new Exception('failed to initialize'); curl_setopt($ch, CURLOPT_URL, 'http://example.com/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt(/* ... */); $content = curl_exec($ch); if (FALSE === $content) throw new Exception(curl_error($ch), curl_errno($ch)); // ...process $content now} catch(Exception $e) { trigger_error(sprintf( 'Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);}
The above is the detailed content of Detailed explanation of how to troubleshoot php curl errors. For more information, please follow other related articles on the PHP Chinese website!