|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-08-30 15:47 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 21:00:01 2025 UTC |
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.