Questions tagged [pcntl]
PCNTL is short for Process Control, a PHP Extension implementing the Unix style of process creation, program execution, signal handling and process termination.
pcntl
171
questions
0
votes
0
answers
35
views
pcntl_fork: parent process stops after child process exits
When the child process created by pcntl_fork() runs exit(0) also the parent process ends.
I say end and not exist, because I see a strange behavior: the request ends with an empty output (with HTTP ...
0
votes
0
answers
42
views
Why does ignoring SIGCHLD cause exit code -1?
This code expectedly outputs "0":
exec('date', $output, $resultCode);
echo $resultCode . PHP_EOL;
However, if I prepend this line:
pcntl_signal(SIGCHLD, SIG_IGN);
then the output is "-...
0
votes
0
answers
180
views
pcntl-fork equivalent with php-fpm
I have recently migrated one of my php applications from hostgator to AWS using the Apache AMI.
The PHP is running with the server API as FMP/FastCGI, my code is currently built for CGI/FastCGI.
With ...
1
vote
0
answers
238
views
change loop uses pcntl_fork by fiber in php 8.1
Can someone help me please, to use fiber on a loop like pcntl_fork to process data in parallel,
Here is the code for converting to fiber, Thanks.
`$names = array('A','B','C','D','E');
$childs = array()...
0
votes
0
answers
214
views
usleep() in while loop causing issues - whole process freezes
I am using php, Laravel, Redis, and SQL on an Ubuntu localhost server. I have made a bunch of methods that return results from API searches after some processing. I am calling 5 of these methods which ...
0
votes
0
answers
626
views
Install/enable PHP 7.4 PCNTL extenstion on Ubuntu 20
I am trying to run php7.4 code as async using package spatie/async but seems to have problem with PCNTL extension.
I have followed this to install pcntl extenstion but have error on step:7
Not sure ...
2
votes
0
answers
2k
views
Enable PHP8.1 extension PCNTL on Ubuntu 22.04 and Docker
I am trying to enable the PCNTL extension for PHP 8.1 on Ubuntu 22.04 but have been unsuccessful.
When I run a command php -i | grep pcntl via terminal it returns pcntl support => enabled but the ...
3
votes
2
answers
764
views
Why doesn't PHP pcntl_fork run more than two child processes in parallel?
I understand how fork() works at a high level and the pcntl_fork() wrapper, but for some reason in my environment PHP only runs two child processes at a time. Take for example this simple code:
<?...
0
votes
1
answer
472
views
pcntl_fork not working when being used with apache but does work from CLI
I have a small mission critical web app that needs to respond to all requests rather fast. I need to run some other code that can potentially take a few seconds. I was trying to use pcntl_fork. If I ...
0
votes
0
answers
51
views
Why do a variable gets overridden in some threads?
I am getting a variable overridden some times(Each time I run the script I get different result) in other threads, or if I split the total threads to run in chunks. Would you explain to me what does ...
0
votes
1
answer
259
views
Is there a way to signal a SIGALRM with a finer-grained delay than pcntl_alarm(int $seconds)?
pcntl_alarm(int $seconds) only has a resolution of seconds. Is there a way in PHP to signal a SIGALRM with a delay of, say, milliseconds? Maybe a posix_kill() with a delay argument?
PS.: I'm aware of ...
1
vote
1
answer
156
views
PHP: proc_get_status exitcode is always -1 after pcntl_fork
I'm having troubles with using proc_get_status after a pcntl_fork in the parent process.
Here's an example with docker and PHP 7.4, but note the PHP version does not matter, the result is the same ...
0
votes
1
answer
118
views
PHP class loaded by child process becomes visible in parent process?
I am trying to add a mechanism for loading classes on demand and then basically unloaded them / being able to reload them. Essentially, each time the class is needed, it should be loaded freshly from ...
0
votes
0
answers
102
views
Yii2 redirect and pcntl_fork
Using Yii2 I have implemented pcntl_fork() in one of my controllers and though the process is working as I need there are a few issues I would like to sort out.
Simplified logic
//Start timer marker
...
1
vote
1
answer
475
views
Handle process signals in Swoole script without pcntl_signal() function
I'm implementing a php parallel tasks script based on Swoole module which works as daemon.
Is it possible to use Swoole functions to handle process signals instead of pcntl_signal()?
<?php
declare(...