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.

Documentation of the PHP PCNTL extension can be found here: https://php.net/pcntl

171 questions
2
votes
1 answer

Can APC improve the speed of CLI scripts when used with pcntl_fork()?

APC works by storing the opcodes from PHP files in shared memory. When PHP is used with a web server (eg Apache) then the shared memory has a long life. When called from the commandline, then the APC cache is created and destroyed for each process.…
dave1010
  • 15,135
  • 7
  • 67
  • 64
2
votes
2 answers

Why is pcntl_fork() disabled in PHP?

I was trying to setup a multi-threaded socket application, but whenever I ran it I got an error because pcntl_fork() was disabled by default. Is this because it is dangerous or unstable? Should I look for some other way to multithread, or is it just…
CoderOfHonor
  • 741
  • 7
  • 17
2
votes
1 answer

pcntl_fork() results in defunct parent process

So, I have this PHP daemon worker that listens to IPC messages. Weird thing is that the parent process (result from pcntl_fork) leaves a [php] < defunct> process untill the child process is done but ONLY when the script is started form a cronjob,…
Milananas
  • 116
  • 2
  • 8
2
votes
1 answer

Checking PCNTL extension installed in PHP

One of background scripts in my project uses PCNTL to fork. Also, I have a requirement checker script that should be run by user before script installation. Since pcntl can be accessed only in CGI mode, both function_exists('pcntl_fork') and…
WindBridges
  • 693
  • 2
  • 11
  • 23
2
votes
2 answers

PHP forking and processing MySQL database without conflict

I have a MySQL database table that I need to process. It takes about 1 second to process 3 rows (due to CURL connections I need to make for each row). So, I need to fork the PHP script in order to have a reasonable time (since I will process up to…
Trevor Gehman
  • 4,645
  • 3
  • 22
  • 25
2
votes
1 answer

Resolving a large amount of IP addresses with PHP

I need to resolve a large amount of IP addresses. I'm using gethostbyaddr() for it. I just recently read about using pcntl_fork() and that if you do fork, you don't have to wait for a timeout. Since gethostbyaddr will take a long time (30 seconds,…
Steve
  • 2,936
  • 5
  • 27
  • 38
1
vote
1 answer

Using pcntl_fork child process cannot access CodeIgniter instance created from parent

I'm trying to write a daemon process using code igniter library, and the problem is when I fork the daemon process it can no longer access the CI instance and all the libraries which were initialized in __construct are also inaccessible plus if I…
Imran Imtiaz
  • 65
  • 1
  • 7
1
vote
0 answers

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(); for ($i=0; $i < count($names) ; $i++) { …
1
vote
0 answers

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 php function extension_loaded('pcntl') returns…
PYovchevski
  • 95
  • 1
  • 13
1
vote
1 answer

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 from at least PHP 7.2 to PHP…
ymarillet
  • 11
  • 1
1
vote
1 answer

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()?
Andrey Lebedev
  • 141
  • 1
  • 9
1
vote
2 answers

PHP pcntl Variable Scope

I want to be able to modify array elements that are in the parent pid. Here is some example code: $arrayContainer = array( array( "id" => 1, "name" => "Lenny" ), array( "id" => 2, "name" =>…
gprime
  • 2,283
  • 7
  • 38
  • 50
1
vote
1 answer

How to compile pcntl for PHP 7.4 and above?

I am attempting to compile the pcntl extension for PHP 7.4 and PHP 8 with the following commands (from Mac): wget "https://www.php.net/distributions/php-7.4.0.tar.gz" tar xvf "php-7.4.0.tar.gz" cd…
Jeremy
  • 3,620
  • 9
  • 43
  • 75
1
vote
0 answers

PHP - pcntl_fork() not running child process

I am running following code. It's only running parent process. $pid = pcntl_fork(); if($pid) { // parent process runs what is here echo $pid; echo "parent\n"; } else { // child process runs what is here echo "child\n"; } Output:…
Tell Me How
  • 672
  • 12
  • 16
1
vote
0 answers

Enabling pcntl_fork on beanstalk aws

I Am using Elastic Beanstalk Linux AMI with PHP. When I run this on the terminal: php -m | grep pcntl I see pcntl but when I try using pcntl_fork() function it doesn't work.
Rais
  • 11
  • 3