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

Detailed explanation of how to troubleshoot php curl errors

黄舟
Release: 2023-03-16 08:16:02
Original
5662 people have browsed it

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);
Copy after login

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));
Copy after login

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);}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template