Hello fellow stacked overflowers..
I am cu
rrently having an issue with PHP's sleep()
method when used in a loop.
I want ability to pause()
a long batch script at any given moment.
In my long batch script I will check for a flag located in memcached; and if set, activated will try and "pause" the script.
Please see below:
session_write_close(); //Apparent Session Induced Fix that Doesn't Work
do {
$halted = $this->memcache->get("halted");
if ($halted) {
sleep(1);
}
} while ($halted);
With the above code I am able to successfully 'pause' my script. Except for the fact that sleep()
appears to block ALL subsequent requests to the server; when in the loop.
I know sleep()
needs to block the current thread to do its thing. But I'm not sure as to why it is blocking all of the subsequent requests.
- Does anyone have any idea as to what might be happening?
- Is there any alternate methods to effectively 'pause' any PHP script mid way?