Doc #77436 [Com]: Missing note about OS specific behavior
| From: | mucahitcucen at gmail dot com | Date: | Fri, 11 Jan 2019 18:47:21 +0000 |
| Subject: | Doc #77436 [Com]: Missing note about OS specific behavior | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-16322@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77436&edit=1
ID: 77436
Comment by: mucahitcucen at gmail dot com
Reported by: kbush at rvhsolutions dot com
Summary: Missing note about OS specific behavior
Status: Open
Type: Documentation Problem
Package: Documentation problem
Operating System: win & nix
PHP Version: 7.2.13
Block user comment: N
Private report: N
New Comment:
Hello,
This is not about sleep function. set_time_limit function causes this conflict.
In the documentation page (http://www.php.net/manual/en/function.set-time-limit.php), you can see a
note about difference between unix and windows.
The note which is i refer:
"The set_time_limit() function and the configuration directive max_execution_time only affect
the execution time of the script itself. Any time spent on activity that happens outside the
execution of the script such as system calls using system(), stream operations, database queries,
etc. is not included when determining the maximum time that the script has been running. This is not
true on Windows where the measured time is real."
Previous Comments:
------------------------------------------------------------------------
[2019-01-10 00:34:05] kbush at rvhsolutions dot com
Description:
------------
---
From manual page: https://php.net/function.sleep
---
The behavior of sleep differs between windows and nix OS's but this behavior is not documented.
Specifically, sleep counts towards max_execution_time in windows but not in nix.
Something is mentioned on the set_time_limit() page but it is not abundantly clear that sleep() time
will be ignored.
Please add a note to the sleep page indicating that the behavior differs between operating systems.
Also, it wouldn't hurt to add sleep() to the note block on set_time_limit after the system()
reference.
Attached some code if you wish to verify this behavior. In windows you get 10 lines, in nix you get
30.
We ran into this issue after migrating some old scripts from windows to nix and occasionally they
seemed to run forever.
PS, if this could be fixed so that sleep does count toward execution time on nix, that would be
best. Because of this difference a script with a 30 second timeout could run for months if stuck in
a loop with sleep in it. That completely invalidates the point of a max execution time...
Test script:
---------------
<?php
set_time_limit(10); $i = 1;
while($i<=30){
echo "1 second has passed and the max_execution_time is:
".ini_get("max_execution_time")." - Run $i times so far...\r\n<br>";
sleep(1); $i++;
}
Expected result:
----------------
1 second has passed and the max_execution_time is: 10 - Run 1 times so far...
1 second has passed and the max_execution_time is: 10 - Run 2 times so far...
1 second has passed and the max_execution_time is: 10 - Run 3 times so far...
1 second has passed and the max_execution_time is: 10 - Run 4 times so far...
1 second has passed and the max_execution_time is: 10 - Run 5 times so far...
1 second has passed and the max_execution_time is: 10 - Run 6 times so far...
1 second has passed and the max_execution_time is: 10 - Run 7 times so far...
1 second has passed and the max_execution_time is: 10 - Run 8 times so far...
1 second has passed and the max_execution_time is: 10 - Run 9 times so far...
1 second has passed and the max_execution_time is: 10 - Run 10 times so far...
( ! ) Fatal error: Maximum execution time of 10 seconds exceeded in test.php on line 6
Actual result:
--------------
1 second has passed and the max_execution_time is: 10 - Run 1 times so far...
1 second has passed and the max_execution_time is: 10 - Run 2 times so far...
1 second has passed and the max_execution_time is: 10 - Run 3 times so far...
1 second has passed and the max_execution_time is: 10 - Run 4 times so far...
1 second has passed and the max_execution_time is: 10 - Run 5 times so far...
1 second has passed and the max_execution_time is: 10 - Run 6 times so far...
1 second has passed and the max_execution_time is: 10 - Run 7 times so far...
1 second has passed and the max_execution_time is: 10 - Run 8 times so far...
1 second has passed and the max_execution_time is: 10 - Run 9 times so far...
1 second has passed and the max_execution_time is: 10 - Run 10 times so far...
1 second has passed and the max_execution_time is: 10 - Run 11 times so far...
1 second has passed and the max_execution_time is: 10 - Run 12 times so far...
1 second has passed and the max_execution_time is: 10 - Run 13 times so far...
1 second has passed and the max_execution_time is: 10 - Run 14 times so far...
1 second has passed and the max_execution_time is: 10 - Run 15 times so far...
1 second has passed and the max_execution_time is: 10 - Run 16 times so far...
1 second has passed and the max_execution_time is: 10 - Run 17 times so far...
1 second has passed and the max_execution_time is: 10 - Run 18 times so far...
1 second has passed and the max_execution_time is: 10 - Run 19 times so far...
1 second has passed and the max_execution_time is: 10 - Run 20 times so far...
1 second has passed and the max_execution_time is: 10 - Run 21 times so far...
1 second has passed and the max_execution_time is: 10 - Run 22 times so far...
1 second has passed and the max_execution_time is: 10 - Run 23 times so far...
1 second has passed and the max_execution_time is: 10 - Run 24 times so far...
1 second has passed and the max_execution_time is: 10 - Run 25 times so far...
1 second has passed and the max_execution_time is: 10 - Run 26 times so far...
1 second has passed and the max_execution_time is: 10 - Run 27 times so far...
1 second has passed and the max_execution_time is: 10 - Run 28 times so far...
1 second has passed and the max_execution_time is: 10 - Run 29 times so far...
1 second has passed and the max_execution_time is: 10 - Run 30 times so far...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77436&edit=1