php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77436 Missing note about OS specific behavior
Submitted: 2019-01-10 00:34 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: kbush at rvhsolutions dot com Assigned:
Status: Open Package: Documentation problem
PHP Version: 7.2.13 OS: win & nix
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-01-10 00:34 UTC] 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... 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-11 18:47 UTC] mucahitcucen at gmail dot com
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."
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Mar 22 06:01:26 2019 UTC