Req #77603 [Asn]: Continued sleep after signal interruption

From: Date: Fri, 08 Dec 2023 12:33:28 +0000
Subject: Req #77603 [Asn]: Continued sleep after signal interruption
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246011@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77603&edit=1

 ID:                 77603
 Updated by:         bukka@php.net
 Reported by:        aliborhani1 at gmail dot com
 Summary:            Continued sleep after signal interruption
 Status:             Assigned
 Type:               Feature/Change Request
 Package:            Program Execution
 Operating System:   Ubuntu 18.04.2 LTS
 PHP Version:        7.3.2
 Assigned To:        bukka
 Block user comment: N
 Private report:     N

 New Comment:

The same is for usleep, time_nanosleep and time_sleep_until


Previous Comments:
------------------------------------------------------------------------
[2023-12-08 12:29:47] 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.

------------------------------------------------------------------------
[2019-02-11 11:53:10] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77603&edit=1


Thread (3 messages)

« previous php.bugs (#246011) next »