|  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
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-02-11 11:53 UTC] aliborhani1 at gmail dot com
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 (cli) (built: Feb  8 2019 15:43:57) ( NTS )
Webserver: Nginx - using unix socket

Test script:

slog("before sleep");

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

// but, this doesn't work:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2023-12-08 12:29 UTC]
-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]
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]
The same is for usleep, time_nanosleep and time_sleep_until
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 04:01:28 2024 UTC