php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81358 PHP hangs when the first signal sent
Submitted: 2021-08-14 02:01 UTC Modified: 2021-08-16 15:25 UTC
From: abolfazl dot ziaratban at gmail dot com Assigned:
Status: Closed Package: Program Execution
PHP Version: 8.0.9 OS: CentOS
Private report: No CVE-ID: None
 [2021-08-14 02:01 UTC] abolfazl dot ziaratban at gmail dot com
Description:
------------
Hi
PHP hangs when I open php with proc_open and send a signal.

Test script:
---------------
test2.php
echo 'Test'; #does not run

test1.php
$proc = proc_open('php test2.php',[],$_);
posix_kill(proc_get_status($proc)['pid'],SIGUSR1);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-14 02:47 UTC] abolfazl dot ziaratban at gmail dot com
-Package: *General Issues +Package: Program Execution
 [2021-08-14 02:47 UTC] abolfazl dot ziaratban at gmail dot com
.
 [2021-08-14 02:49 UTC] abolfazl dot ziaratban at gmail dot com
fix bug :
$proc = proc_open('php test2.php',[],$_);
sleep(1); #fix
posix_kill(proc_get_status($proc)['pid'],SIGUSR1);
 [2021-08-16 12:35 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2021-08-16 12:35 UTC] nikic@php.net
Can you clarify what the actual issue here is? Is it the "does not run" part? That seems expected to me, because the SIGUSR1 default action is to terminate the process, so if the signal arrives before the echo can execute, nothing will be printed.

Or is there an actual hang here, and if so, how does it look like. Does the outer "php test1.php" call itself hang indefinitely?
 [2021-08-16 15:10 UTC] abolfazl dot ziaratban at gmail dot com
-Status: Feedback +Status: Open
 [2021-08-16 15:10 UTC] abolfazl dot ziaratban at gmail dot com
The main problem is : test2.php does not run when sending SIGUSR1.

> because the SIGUSR1 default action is to terminate the process
Why?

SIGUSR1 and SIGUSR2 are User-defined signals.
I thought these signals were for me.
Why the php using this signals for terminate the process?

Ok i put assume that signals are for terminate the process but why does the SIGALRM signal behave similarly(acts like SIGUSR1)?


New Example :

test1.php
$proc = proc_open('php /root/test2.php',[],$p);
posix_kill(proc_get_status($proc)['pid'],SIGALRM);

while(proc_get_status($proc)['running'])
    sleep(1);

echo "End !";


test2.php
mkdir('/root/a');

In this example, directory `a` is not created and test2.php does not actually run.
 [2021-08-16 15:15 UTC] nikic@php.net
> SIGUSR1 and SIGUSR2 are User-defined signals.
> I thought these signals were for me.
> Why the php using this signals for terminate the process?

PHP isn't doing anything -- signals have a default disposition, which is Terminate for all of SIGALRM, SIGUSR1 and SIGUSR2. Check "man 7 signal" for a list of default dispositions.

You can define a custom signal action using pcntl_signal(), which will override the default disposition. Of course, it will only take effect after the pcntl_signal() call actually happens, so it won't make a difference if SIGUSR1 arrives too early.
 [2021-08-16 15:25 UTC] abolfazl dot ziaratban at gmail dot com
-Status: Open +Status: Closed
 [2021-08-16 15:25 UTC] abolfazl dot ziaratban at gmail dot com
Yes, I realized.
I did not pay attention to their default value. 


nikic thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 21:01:31 2024 UTC