php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77603 Continued sleep after signal interruption
Submitted: 2019-02-11 11:53 UTC Modified: 2023-12-08 12:33 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: aliborhani1 at gmail dot com Assigned: bukka (profile)
Status: Assigned Package: Program Execution
PHP Version: 7.3.2 OS: Ubuntu 18.04.2 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: aliborhani1 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-02-11 11:53 UTC] aliborhani1 at gmail dot com
Description:
------------
When I use sleep() method in my script and set `process_control_timeout` to `20s` in php-fpm.conf, I see unexpected behavior when I reload the php-fpm. It seems it doesn't respect the sleep's argument (e.g. 10 seconds) and wakes up the script too early. 

However, when I use `exec('sleep 10')` instead, it works correctly:


```
[02-11-2019 11:39:15] before sleep
[02-11-2019 11:39:25] after sleep
[02-11-2019 11:39:25] after echo
```


PHP Version: PHP 7.3.2-3+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Feb  8 2019 15:43:57) ( NTS )
Webserver: Nginx - using unix socket

Test script:
---------------
<?php

slog("before sleep");

// this works:
// exec('sleep 10');

// but, this doesn't work:
sleep(10);

slog("after sleep");

echo "Done!" . PHP_EOL;
slog("after echo");


function slog(string $text) {
    $text = '[' . strftime("%m-%d-%Y %H:%M:%S") . '] ' . $text . PHP_EOL;
    file_put_contents(__DIR__ . '/app.log', $text, FILE_APPEND);
}

Expected result:
----------------
[02-11-2019 11:38:43] before sleep
[02-11-2019 11:38:53] after sleep
[02-11-2019 11:38:53] after echo

Actual result:
--------------
[02-11-2019 11:38:43] before sleep
[02-11-2019 11:38:46] after sleep
[02-11-2019 11:38:46] after echo

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2023-12-08 12:29 UTC] bukka@php.net
-Summary: Unexpected behavior with reloading php-fpm and sleep method +Summary: Continued sleep after signal interruption -Type: Bug +Type: Feature/Change Request -Package: FPM related +Package: Program Execution -Assigned To: +Assigned To: bukka
 [2023-12-08 12:29 UTC] bukka@php.net
I have been testing and thinking about this and I don't think this should be considered as a bug. The reason is that sleep is signal interruptable so it behaves like in C. I see however a use case for continued sleep after the signal handling so I think we should consider some additional parameter for sleep method or even change of the default. It needs to be handled as a feature though and it is not an FPM issue but more a standard ext issues.
 [2023-12-08 12:33 UTC] bukka@php.net
The same is for usleep, time_nanosleep and time_sleep_until
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC