Why does session_start cause a timeout when one script calls another script using curl


Answers

I don't totally understand why this happens, but I got it solved.

This bug describes the same problem I'm having. I have a scripts posting to another script, both using the same session, which apparently stalls PHP.

So, before I do the whole curl post script, I call the session_commit function, so ending the calling scripts session, and enabling the called script to restart the session.

Whack...

Question

I have two PHP scripts, both using the same session by calling session_name('MySessID').

When the first script calls the second script using curl, the second script hangs when session_start() is called.

Why would this happend?




PHP session_start serializes and blocks all others sharing the same session

Possible duplicates:

How does session_start lock in PHP?

Why does session_start cause a timeout when one script calls another script using curl

session_start hangs

How to kill a PHP session?

... And many ;)

Edit

  1. The reason why it blocks is because the session file is being read and it might be modified at any point of time when the first script is running, hence the lock.

  2. The remedy to this could be a session_write_close() as pointed by this post

  3. How to prevent blocking php requests, by Konr Ness




How to kill a PHP session?

Maybe you can give a timeout to the socket? e.g. socket_select has a timeout parameter.

The value of 1000s as timeout may be too high, because apache may have killed the process before (see max_execution_time in php.ini)







Tags