<p>I'm running Apache on Linux within VMWare.</p>
<p>One of the PHP pages I'm requesting does a <code>sleep()</code>, and I find that if I attempt to request a second page whilst the first page is <code>sleep()'ing</code>, the second page hangs, waiting for the <code>sleep()</code> from the first page to finish.</p>
<p><strong>Has anyone else seen this behaviour?</strong></p>
<p>I know that <a href="http://php.net/" rel="nofollow noreferrer">PHP</a> isn't <strong>multi-threaded</strong>, but this seems like gross mishandling of the CPU.</p>
<p><strong>Edit</strong>: I should've mentioned that the CPU usage doesn't spike. What I mean by CPU &quot;hogging&quot; is that no other PHP page seems able to use the CPU whilst the page is sleep()'ing.</p>

[{'answer_id': 21417, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 1, 'selected': False, 'text': "<p>Are you actually seeing the CPU go to 100% or just that no other pages are being served? How many apache-instances are you runnning? Are they all stopping when you run sleep() in of of the threads?</p>\n\n<p>PHP's sleep() function essentially runs through an idle loop for n seconds. It doesn't release any memory, but it should not increase CPU load significantly.</p>\n"}, {'answer_id': 22425, 'author': 'rix0rrr', 'author_id': 2474, 'author_profile': 'https://Stackoverflow.com/users/2474', 'pm_score': 2, 'selected': False, 'text': '<p>What this probably means is that your Apache is only using 1 child process.</p>\n\n<p>Therefore: </p>\n\n<p>The 1 child process is handling a request (in this case sleeping but it could be doing real work, Apache can\'t tell the difference), so when a new request comes it, it will have to wait until the first process is done.</p>\n\n<p>The solution would be to increase the number of child processes Apache is allowed to spawn (<a href="http://httpd.apache.org/docs/2.0/mod/mpm_common.html#maxclients" rel="nofollow noreferrer">MaxClients</a> directive if you\'re using the prefork MPM), simply remove the sleep() from the PHP script.</p>\n\n<p>Without exactly knowing what\'s going on in your script it\'s hard to say, but you can probably get rid of the sleep().</p>\n'}, {'answer_id': 498675, 'author': 'Manuel', 'author_id': 1139600, 'author_profile': 'https://Stackoverflow.com/users/1139600', 'pm_score': 4, 'selected': False, 'text': '<p>It could be that the called page opens a session and then doesn\'t commit it, in this case see <a href="https://stackoverflow.com/questions/498477/php-serving-one-page-at-a-time/498497#498497">this answer</a> for a solution.</p>\n'}]
['https://Stackoverflow.com/questions/21411', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1693/']