Edit report at https://bugs.php.net/bug.php?id=65596&edit=1

 ID:                 65596
 Updated by:         johan...@php.net
 Reported by:        ukrtelecom at gmail dot com
 Summary:            usleep prevents script timeout
-Status:             Wont fix
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   Linux
 PHP Version:        5.4Git-2013-08-30 (snap)
 Block user comment: N
 Private report:     N

 New Comment:

What happens depends on the operating system, in general we tr tomeasure the 
time spent on cpu, not the time elapsed.

On systems which have setitimer (Linux and other unixes) we use setitimer with 
ITIMER_PROF, which, in my linux system's man page is documented as

       ITIMER_PROF    decrements both when the process executes and when the 
                      system is executing on behalf  of  the  process. 
 
During sleep nothing is being executed.


Previous Comments:
------------------------------------------------------------------------
[2013-08-30 18:26:45] anon at anon dot anon

@ab Well of course it's solvable.
1. sleepTime = min(specifiedTime, timeLimit - scriptTime)
2. Do system call.
3. scriptTime += sleepTime

I don't understand why you track script time in such a bizarre fashion that it 
somehow doesn't contribute to the time limit anyway.

------------------------------------------------------------------------
[2013-08-30 18:00:25] a...@php.net

This is unsolvable in PHP, sleep is a system call so it will suspend the 
execution 
. It can be only interrupted by a signal which can't be thrown from PHP because 
the execution is suspended :)

------------------------------------------------------------------------
[2013-08-30 15:47:44] ukrtelecom at gmail dot com

Description:
------------
Usleeped time does not count in total timeout time.

Commenting out line 11 "usleep(10)" in the test script results with expected 
Fatal timeout in 2 seconds.
Enabling line 11 "usleep(10)" makes script exit by condition in 50 seconds.
Increasing waiting time to 100 seconds in line 2 results with timeout Fatal 
error in 60-70 sec.


PHP 5.4.20-dev (cli) (built: Aug 30 2013 14:18:16) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

./configure --disable-libxml --disable-xml --disable-simplexml --disable-
xmlreader --disable-xmlwriter --disable-dom --without-pear

OS Ubuntu 12.04 LTS 
Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 
x86_64 x86_64 x86_64 GNU/Linux

Test script:
---------------
<?php
$wait = 50;

echo ini_get('max_execution_time');

set_time_limit(2);

$ts = time();
while(true) {
        // usleep for 10 microseconds
        usleep(10);
        if ((time()- $ts) > $wait) {
                echo time() -$ts;
                echo "\n\nFailed! " . ini_get('max_execution_time') . "\n";
                break;
        }
}



Expected result:
----------------
0
Fatal error: Maximum execution time of 2 seconds exceeded in 
/home/vagrant/t.php 
on line 12

Actual result:
--------------
#with wait time 50 sec:
$ date; php t.php ; date
Fri Aug 30 15:40:54 UTC 2013
0
51

Failed! 2
Fri Aug 30 15:41:45 UTC 2013


#with wait time 100 sec:
$ date; php t.php ; date
Fri Aug 30 15:35:45 UTC 2013
0

Fatal error: Maximum execution time of 2 seconds exceeded in 
/home/vagrant/t.php 
on line 12
Fri Aug 30 15:36:40 UTC 2013



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65596&edit=1

Reply via email to