1

I have a basic install of Apache2 server and PHP5.3 on my local Ubuntu machine.

I created file index.php and put sleep 30 seconds in it

<?php
sleep(30); // script sleep 30s
?>

When i run "localhost/index.php" in web browser, request are waiting that 30 seconds.

During that time I delete that line sleep(30); and run in new tab "localhost/index.php"

Second request is waiting first to finish, so wait that 30s.

That is a problem because Apache run only one process/thread. How to configure Apache to run normally? Or can someone explain to me what's going on?

tasmaniski
  • 123
  • 6
  • How did you establish that the second request was waiting for the first one to finish, rather than just sleeping 30 seconds? Did you wait ten seconds and then time it, for example? It's *much* more likely that it was simply getting a cached copy of the script with the sleep in it. – David Schwartz Dec 18 '12 at 11:49
  • I tried that and it's the same thing. Second request wait first, and after 30s second, wait regular 10 seconds to give response. – tasmaniski Dec 18 '12 at 11:57

2 Answers2

1

You probably have a deadlock on the session file; turn off session.auto_start, and/or call session_write_close() before sleep(30).

TML
  • 358
  • 2
  • 9
0

It's related to PHP's session. The session file (that bizarre file that is on /tmp/SOMETHING) gets locked for the first request.

You should call session_write_close() before the sleep() (or any time-wasting call). You might disable session_autostart if you don't want to use it either.

slm
  • 7,355
  • 16
  • 54
  • 72
Vitor
  • 1