Bug #74563 [Opn]: curl_exec() throws internal error in curl_error()

From: Date: Tue, 09 May 2017 21:59:22 +0000
Subject: Bug #74563 [Opn]: curl_exec() throws internal error in curl_error()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209033@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74563&edit=1

 ID:                 74563
 Updated by:         danack@php.net
 Reported by:        jeremys at ha dot com
 Summary:            curl_exec() throws internal error in curl_error()
 Status:             Open
 Type:               Bug
 Package:            cURL related
 Operating System:   RHEL 7.3
 PHP Version:        7.1.4
 Block user comment: N
 Private report:     N

 New Comment:

> I disabled opcache for the script by adding the following line to the top of the script:
> ini_set( 'opcache.enable', 0 );

If the script is being cached, then editing the script won't make a difference.

Please try editing what is being printed out in the error handler, to confirm the exact code
you're reporting is causing the error.

The reason I'm so sceptical about what code is making that error appear, is that the error
message is one that is shown when userland code calls an internal function, but is very unlikely to
appear due to how curl works internally.


Previous Comments:
------------------------------------------------------------------------
[2017-05-09 15:32:58] jeremys at ha dot com

No Suhosin or other security modules are running/enabled. Do you need a particular part of the
php.ini?

I disabled opcache for the script by adding the following line to the top of the script:
ini_set( 'opcache.enable', 0 );

And the error still occasionally happens.

------------------------------------------------------------------------
[2017-05-09 15:16:06] danack@php.net

In fact - please can you just double check that you are seeing the error from the code you have
listed here.

I strongly suspect you have OPCache running and the error you are seeing is from code that has been
cached in memory, rather than running the latest version of that file.

------------------------------------------------------------------------
[2017-05-09 15:04:57] danack@php.net

Do you have Suhosin or any other security module enabled?

------------------------------------------------------------------------
[2017-05-09 13:58:27] 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
)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74563&edit=1


Thread (9 messages)

« previous php.bugs (#209033) next »