curl_init() silently returns NULL

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Curl had been working from PHP and then stopped working, possibly
related to upgrade of PHP from 5.1.6 to 5.2.13.  The problem is
demonstrated by running the following script on my system, which
displays a NULL return from php_init:

$h= curl_init();

According to the documentation, curl_init should return a handle or
FALSE upon failure.  Note that NULL is returned rather than FALSE.
There are no other messages sent to stdout or stderr.

curl_init() returns NULL whether using the PHP cli or sapi.

The system is running Centos 5.5 x86-64

Here are some things I've tried, hoping that they would clear the
error, none fixed the problem:

-restarted Apache
-downgraded back to php5.1.6. Subsequently re-upgraded back to 5.2.13
when the downgrade did not resolve the problem.
-yum remove and then reinstall of php and curl

At this point I am out of options for clearing the problem or
debugging it.

Re: curl_init() silently returns NULL

Quoted text here. Click to load it

Don't use var_export() for debugging, use var_dump().  If you use
var_export() on a resource type, it seems to represent it as NULL.

Using var_dump(), you should see output that looks something like:

  resource(2) of type (curl)


Curtis Dyer

Re: curl_init() silently returns NULL

Quoted text here. Click to load it
Thanks.  A fine point worthy of a note added to the documentation.  In
this case the test script blinded me to the fact that the problem was
resolved.  The more complex script that had been failing at
curl_init(), which initially got me into this line of investigation,
is now working.  I guess one of the interventions I took to fix the
problem worked, but I did not realize it because of the faulty test.

Re: curl_init() silently returns NULL

El 18/06/2010 1:36, escribió/wrote:
Quoted text here. Click to load it

It's actually documented in the page for var_export():

"Note: Variables of type resource couldn't be exported by this function."

But I guess you would never look there when debugging something else :)

Be also aware that there are cases where even var_dump() is not
reliable, for instance with SimpleXML objects, which generate strings on
the fly.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Site Timeline