|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52173 ext/pcntl doesn't store/report errors
Submitted: 2010-06-24 16:40 UTC Modified: 2017-01-28 11:27 UTC
Avg. Score:3.7 ± 1.5
Reproduced:7 of 7 (100.0%)
Same Version:6 (85.7%)
Same OS:4 (57.1%)
From: nick dot telford at gmail dot com Assigned:
Status: Open Package: PCNTL related
PHP Version: trunk-SVN-2010-06-24 (SVN) OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-06-24 16:40 UTC] nick dot telford at gmail dot com
The following ext/pcntl extensions "return -1 on failure", yet have multiple 
possible reasons for failure: pcntl_fork, pcntl_wait, pcntl_waitpid

Each of these functions can fail for several reasons and in some cases 
(especially wait/waitpid) it is useful for the userland code to be able to 
handle the different error codes.

The Linux man pages for fork(2) and wait/waitpid(2) all specify that the error 
code is stored in "errno" when an error occurs. I only have experience of the 
System V (Linux) way, so I'm not sure if this is interoperable, although I 
believe so.

The ext/posix function posix_get_last_error() states that it returns the error 
code for the last posix function that failed. Internally, all of these functions 
also use "errno" to store the error code, but explicitly copy that to another 
variable, which posix_get_last_error() returns 

I see two possible solutions, either:
 - posix_get_last_error() should be used to return these errors. Although this 
would add a dependency between the two extensions.
 - An optional parameter, &$errno, should be added to pcntl_fork(), pcntl_wait() 
and pcntl_waitpid() that is populated with errno if the result is -1.
 - A function is added to ext/pcntl, pcntl_get_last_error(), that operates in a 
similar way to posix_get_last_error().

The third option seems simplest and most compatible, although I can't help but 
feel these two extensions really belong together as one big happy family. What's 
the reason they're separate in the first place?

Test script:
$pid = pcntl_wait($s);
var_dump($pid, posix_get_last_error());

Expected result:
int(10) # ECHILD

Actual result:


pcntl_get_last_error-bug52173 (last revision 2010-06-24 17:06 UTC by nick dot telford at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-24 16:58 UTC] nick dot telford at gmail dot com
Minor addendum: A solid use-case as to why it is useful for the userland code to 
read the error code.

When calling pcntl_wait(), -1 will be returned if there are no child processes 
running (errno == ECHILD) and also if the call is interrupted by a signal (errno 
== EINTR).

This makes determining whether there are children left to wait on tricky, as -1 
could simply be an interrupt from a signal being handled.
 [2010-06-24 18:19 UTC]
I like option #3.
 [2010-06-24 19:10 UTC] nick dot telford at gmail dot com
I've attached a patch that implements solution #3.

The patch used the extent of my amazing copy/paste skills to extract the 
posix_get_last_error() and posix_strerror() functionality from ext/posix and 
duplicate it in ext/pcntl.

If there's anything wrong with this patch, please let me know. But let me down 
lately - this is the first time I've written (if you can call it that) any C, 
let alone worked on a PHP extension. We've all gotta start somewhere :)

If you need me to write tests etc. please let me know, also any tips on how to 
go about doing so.

I've tested this using the example in the description and it works a treat.
 [2010-11-01 21:10 UTC]
Automatic comment from SVN on behalf of lbarnaud
Log: Fix bug #52173 (ext/pcntl doesn't store/report errors) (patch
by nick dot telford at gmail dot com)
 [2010-11-01 21:22 UTC]
Automatic comment from SVN on behalf of lbarnaud
Log: MFH Fix bug #52173 (ext/pcntl doesn't store/report errors)
(patch by nick dot telford at gmail dot com)
 [2010-11-01 21:23 UTC]
-Status: Open +Status: To be documented
 [2010-11-01 21:23 UTC]
Fixed, thanks !
 [2011-11-16 14:21 UTC]
-Package: PCNTL related +Package: Documentation problem
 [2015-05-08 17:26 UTC]
-Type: Bug +Type: Documentation Problem
 [2017-01-28 11:27 UTC]
-Package: Documentation problem +Package: PCNTL related
 [2022-12-03 06:26 UTC] Ericu98909coy at gmail dot com
Run composer with the --ignore-platform-reqs option and specify pcntl and posix

composer install --ignore-platform-reqs

 [2023-01-09 12:20 UTC] Vincent48Sabin at gmail dot com
Here's what I've found in Ubuntu 12.04:

Check your PHP.ini for the pnctl functions being disabled.

disable_functions =     pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority
phpinfo reports the function is already loaded but it will not actually work without putting the pcntl.ini file into /etc/php5/conf.d.

 [2023-06-19 16:57 UTC] myhealthatvanderbilt dot online at gmail dot com
Nice post! We do our best to stay compliant. We don't need issues.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 07:01:29 2024 UTC