|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-05-09 13:58 UTC] jeremys at ha dot com
Description:
------------
Executing curl_exec() with a host/URL that refuses the connection makes curl_exec() sometimes raise an E_WARNING because curl_exec() calls curl_error() internally. The error is as follows:
curl_error() expects parameter 1 to be resource, boolean given
As you can see in the sample script, there is no explicit call to curl_error(), yet the above error is seen.
I've only been able to reproduce via Apache, not via cli.
Apache/2.4.6 (Red Hat Enterprise Linux)
PHP 7.1.3 (part of Zend Server 9.1) - I assume 7.1.4 as well since there are no relevant changes to the curl interface in the PHP source code
libcurl 7.29.0
Test script:
---------------
<?php
ini_set( 'display_errors', 1 );
ini_set( 'error_reporting', E_ALL );
set_error_handler( function ( ...$error ) {
array_pop( $error );
print_r( $error );
die();
});
$resource = curl_init();
curl_setopt( $resource, CURLOPT_URL, 'http://127.0.0.1:1' );
curl_setopt( $resource, CURLOPT_RETURNTRANSFER, 1 );
curl_exec( $resource );
echo 'Script finished.';
Expected result:
----------------
Script finished.
Actual result:
--------------
Array
(
[0] => 2
[1] => curl_error() expects parameter 1 to be resource, boolean given
[2] => /usr/local/apache/htdocs2/curl-error-test.php
[3] => 16
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 12:00:01 2025 UTC |
I appreciate your skepticism as I was quite skeptical such an error could occur, too, but alas.. With the opcache.enable directive still set to 0, I changed the die in the anonymous error handler function to print 'Error occurred.', and still received the following output (note the different line number and additional string printed at the end): Array ( [0] => 2 [1] => curl_error() expects parameter 1 to be resource, boolean given [2] => /usr/local/apache/htdocs2/common/curl-error-test.php [3] => 18 ) Error occurred.