POST with curl causing Apache to lock up

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

Threaded View
Can anyone help or offer some explanation with this problem:

I'm trying to do a POST from one of my PHP pages, to another page on my
site using curl.
To maintain the session I'm sending the current session cookie in the
headers using

        $headerArray = array("Cookie: " . session_name() . "=" .


        curl_setopt( $ch, CURLOPT_HEADER, 1 );
        curl_setopt( $ch, CURLOPT_POST, 1 );
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $postArray );
        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0 );
        curl_setopt( $ch, CURLOPT_HTTPHEADER, $headerArray);
        curl_exec( $ch );

The problem is, once this is submitted, Apache goes into an infinite
loop and has to be restarted.  This only happens when I send the
current session cookie, if I change it slightly there's no problem
(although obviously the session is lost).

There seems to be mention of a similar problem on the post called 'CURL
and $_SESSION problem' but the guy is trying to achieve something
different so it doesn't get addressed.

Very grateful for any help with this!

Re: POST with curl causing Apache to lock up


on 04/07/2006 07:14 AM Leo said the following:
Quoted text here. Click to load it

It seems like a bug in the Curl library.

You may want to try this HTTP client class. You can enable debug output
and see the HTTP dialog to figure exactly what is going on. It supports
cookie handling, so it should work for your purposes:


Manuel Lemos

Metastorage - Data object relational mapping layer generator

PHP Classes - Free ready to use OOP components written in PHP

Re: POST with curl causing Apache to lock up

Quoted text here. Click to load it

As I recall, PHP locks sessions so the same session can't be used
simultaneously by two different hits in the same session.  If it
didn't do this you'd have to lock session variables in individual
PHP pages to avoid getting a mess when two PHP scripts try to update
the same variables simultaneously.  (For instance, a per-session
hit counter might lose counts).

Ordinarily, hits from the same session (e.g. the page and associated
images, or the page and several frames, which might also be delivered
by PHP pages) are just delayed.  However, if Page A tries to use
PHP to make a hit on Page B on the same server using the same
session, PHP won't start running the Page B code until Page A
finishes running, but Page A won't finish running until Page B is
finished outputting.  DEADLOCK!

The only solution I know of is to call session_write_close() in
Page A before starting the hit on Page B.  This means you can't
change any session variables in Page A (and have the changes take)
after this point.  Another workaround is to NOT try to use the same
session (which may have its own significant problems, like having
to log in with CURL).

                        Gordon L. Burditt

Re: POST with curl causing Apache to lock up

Thanks for the answers, I'll give the session_write_close a try as I'm
calling exit() straight after the curl post anyway.


Site Timeline