7

While running an infinite loop in PHP on Apache, others pages/scripts would hang (take forever to load) until I break execution of the script. However, other pages would still execute on a different user session or browser. Can this be resolved?

B00T3D
  • 73
  • 4
  • How many CPU's are there in your machine? How many threads are running in apache? I would have thought that multiple scripts would be able to run at the same time, in general. Maybe you need: http://httpd.apache.org/docs/2.2/mod/worker.html (I'm assuming your "infinite" is just a "while(1) ;" or some such, and not something more complex that may cause locking conflicts with your main.php) – Mats Petersson Dec 24 '12 at 13:13
  • Does your infinite script need sessions? If not, you could run it from the command line. Although php might not be the right tool to keep a program running... – jeroen Dec 24 '12 at 13:14
  • 1
    You could try to use a dedicated / special session ID for your infinite running script. Just make sure it cannot clash with your normal session ID's – jeroen Dec 24 '12 at 13:23

1 Answers1

5

This is a race condition problem.

Once you session_start() a session, a file attached to the session id is opened with restrictive permissions (locked for reading and writing). If another session_start() is called, it will wait for the session file to be unlocked, to avoid the second script to modify asynchronously the session.

Have a look to this article which explain better than me what's happen.

Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153
  • 4
    That's not the definition of a "race condition", it's a simple locked resource. Correct answer though. – deceze Dec 24 '12 at 13:49