Home  >  Article  >  Backend Development  >  Detailed explanation of how to troubleshoot php curl errors

Detailed explanation of how to troubleshoot php curl errors

黄舟
黄舟Original
2017-09-16 09:47:375440browse

php curl common errors: SSL error, bool(false)

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() and curl_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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn