php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61873 proc_get_status always returns exitcode -1
Submitted: 2012-04-28 03:13 UTC Modified: 2016-06-29 18:26 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: dcb at insomniacsoft dot com Assigned: cmb (profile)
Status: Duplicate Package: Program Execution
PHP Version: 5.4.1 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dcb at insomniacsoft dot com
New email:
PHP Version: OS:

 

 [2012-04-28 03:13 UTC] dcb at insomniacsoft dot com
Description:
------------
Since PHP 5.4.0 the proc_get_status and proc_close functions always return -1 as 
exitcode.

Test script:
---------------
$descriptorspec = array(
    0 => array("pipe", "r"), 
    1 => array("pipe", "w"),
    2 => array("file", "/tmp/error-output.txt", "a")
);
$p = proc_open('/tmp/te', $descriptorspec, $pipes, '/tmp');
sleep(1);
fclose($pipes[0]);fclose($pipes[1]);
$s = proc_get_status($p);
print_r($s);

/tmp/te is simply:
#!/bin/bash
exit 0

Expected result:
----------------
Array
(
    [command] => /tmp/te
    [pid] => 12376
    [running] => 
    [signaled] => 
    [stopped] => 
    [exitcode] => 0
    [termsig] => 0
    [stopsig] => 0
)

Actual result:
--------------
Array
(
    [command] => /tmp/te
    [pid] => 12376
    [running] => 
    [signaled] => 
    [stopped] => 
    [exitcode] => -1
    [termsig] => 0
    [stopsig] => 0
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-28 04:00 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2012-04-28 04:00 UTC] laruence@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I can not reproduce this with php5.4-trunk.
 [2012-04-28 11:25 UTC] dcb at insomniacsoft dot com
I've just tried now with latest snapshot and I'm getting the same result. 
I have this problem occurring on 2 64bit Ubuntu machines.
What OS have you tried to reproduce this on?
 [2012-04-28 11:25 UTC] dcb at insomniacsoft dot com
-Status: Feedback +Status: Open
 [2012-04-28 11:30 UTC] dcb at insomniacsoft dot com
I forgot to mention that on the same machines php 5.3 gives the expected results.
 [2012-04-28 14:22 UTC] reeze dot xia at gmail dot com
I can't reproduce it either. Any error log in /tmp/error-output.txt?
maybe /tmp/te did't have execution permission?
 [2012-04-29 00:18 UTC] dcb at insomniacsoft dot com
I've checked that, the script executes fine and besides I actually discovered the 
issue while working with the symfony/Process classes. On php 5.3.6 all the tests 
pass, but on the same machine, with the same config (just different paths) all 
versions starting from 5.4.0 fail the symfony/Process unit tests related to the 
exit code.
 [2012-04-29 03:51 UTC] laruence@php.net
what about call "/bin/ls" instead of /tmp/te?
 [2012-04-29 03:52 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2012-04-29 06:36 UTC] phpmpan at mpan dot pl
Maybe strace shows something interesting?

strace -f php -r '$descriptorspec = array(
    0 => array("pipe", "r"), 
    1 => array("pipe", "w"),
    2 => array("file", "/tmp/error-output.txt", "a")
);
$p = proc_open("/tmp/te", $descriptorspec, $pipes, "/tmp");
sleep(1);
fclose($pipes[0]);fclose($pipes[1]);
$s = proc_get_status($p);
print_r($s);' 2>&1 | grep '/tmp/te'
 [2012-04-30 23:24 UTC] dcb at insomniacsoft dot com
Still getting -1 for /bin/ls as well
I did the strace, here is output, unfortunately I have no idea how to interpret 
it:
[pid 26199] execve("/bin/sh", ["sh", "-c", "/tmp/te"], [/* 19 vars */] 
<unfinished 
...>
[pid 26200] execve("/tmp/te", ["/tmp/te"], [/* 19 vars */]) = 0
[pid 26200] open("/tmp/te", O_RDONLY)   = 3
write(1, "/tmp/te", 7/tmp/te)                  = 7
 [2012-04-30 23:24 UTC] dcb at insomniacsoft dot com
-Status: Feedback +Status: Open
 [2012-05-01 00:27 UTC] phpmpan at mpan dot pl
Since no one was able to reproduce this to this point, all that can be done is debugging it somehow on your side and eliminate possible reasons.

What strace output tells us here is that "/tmp/te" actually exists and you the code is executing it. In other case the second call to `execve` would not return 0. If it is returning 0, it means that the interpretation of "/tmp/te" has actually started.

He's my output for comparison (snaps for 5.4 and trunk):
-------------------------------
[pid  7359] execve("/bin/sh", ["sh", "-c", "/tmp/te"], [/* 47 vars */] <unfinished ...>
[pid  7359] execve("/tmp/te", ["/tmp/te"], [/* 46 vars */]) = 0
[pid  7359] open("/tmp/te", O_RDONLY)   = 3
write(1, "/tmp/te", 7/tmp/te)                  = 7
-------------------------------

What is puzzling me is why your `sh` (pid:26199) is not replacing itself with the script. As we can see, another process (pid:26200) is spawned and it is the one that executes your script. My blind guess is that PHP receives status code from 26199, which - for some reason - is not waiting for 26200 or not passing the status code from it properly.

Can you check what is this producing?
-------------------------------
sh -c /tmp/te
echo $?
-------------------------------

Maybe the bug is not in PHP...
 [2012-05-01 00:28 UTC] phpmpan at mpan dot pl
"and you the code is executing it. In other"
should be:
"and the code is executing it. In the other"
Sorry
 [2012-05-01 01:12 UTC] dcb at insomniacsoft dot com
Well, that is returning the proper exit code. 

It's strange that nobody else can reproduce this while I have it happening on 2 
different Ubuntu machines. One is a 10.04 and the other one is 11.10.
I was thinking that it might be something else, but keep in mind that on the same 
machine php 5.3 does work properly and returns the correct exit code in all the 
tests.
 [2012-05-01 16:18 UTC] phpmpan at mpan dot pl
Have you tried testing this on non-Ubuntu box? Maybe it's something that depends on Ubuntu configuration?

I still don't like the fact that a second process is spawned after the one PHP is starting.
The following code should also show calls to `wait` and values that are returned from processes.
------------------------------------------
strace -f php -r '$descriptorspec = array(
    0 => array("pipe", "r"), 
    1 => array("pipe", "w"),
    2 => array("file", "/tmp/error-output.txt", "a")
);
$p = proc_open("/tmp/te", $descriptorspec, $pipes, "/tmp");
sleep(1);
fclose($pipes[0]);fclose($pipes[1]);
$s = proc_get_status($p);
print_r($s);' 2>&1 | grep '/tmp/te\|wait'
------------------------------------------
 [2012-05-02 21:49 UTC] dcb at insomniacsoft dot com
Ok, I think I've solved it. After some other tests I figured out it was a build config issue and in the end I 
narrowed it down to --enable-sigchild. I don't know why and without really understanding what it does I added 
that config option when I moved to php 5.4. It also breaks php 5.3. I've tested with php 5.3.6, 5.3.11 and 5.4.1 
and after a clean build without --enable-sigchild proc_get_status will return the correct exitcode.

I did a bit of research and found this article: 
https://blogs.oracle.com/opal/entry/php_oci8_signal_handling_and_e_1

Unfortunately I couldn't find the other bugs reporting this issue, but if they exist then this should be closed.
 [2016-06-29 18:26 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2016-06-29 18:26 UTC] cmb@php.net
> Unfortunately I couldn't find the other bugs reporting this
> issue, but if they exist then this should be closed.

There have been several related reports over the years, the most
recent being bug #71804 which I have just closed after fixing the
docs. I'm marking this ticket as duplicate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 17:01:29 2024 UTC