473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

pcntl_fork problem

Hi,
I'm trying to use pcntl_fork to speedup some checks I do on remote
servers. The problem is the 2nd child is created only when the 1st has
finished the execution of the whole inner for block.

here's the code:

$childs=0; //contatore childs
for ($childs=0; $childs<MAX_THREADS;$childs++) { //MAX_THREADS is the
maximum
//number of forks to
be done
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
print "Child $childs has pid $pid\n";
} else {
print "in child $childs\n";
for ($z=0;$z<$limit;$z++) {
myVeryLongFunction();
};
exit($childs);
};
};
if ($pid) {
while ($childs>0) {
$cid=pcntl_waitpid(-1,&$status);
print "Child $cid exited with status $status\n";
$childs--;
};
print "parent terminated\n";
};

How can I have all the child processes run at the same time without
waiting for the previous child to exit ?

TIA

giuliano

Aug 11 '05 #1
0 1135

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yawnmoth | last post by:
php.net's docs on pcntl_fork aren't exactly clear on how to spawn multiple child processes... i tried something like this, but it didn't seem to work: <? $pid1 = pcntl_fork(); $pid2 =...
117
by: Peter Olcott | last post by:
www.halting-problem.com
1
by: Lisa Pearlson | last post by:
Hi, I wish to write a little server script. It receives binary data and sends it back. Communication goes back and forth, so using apache is not possible. My little script will be a shell...
3
by: cmarvel | last post by:
All: I have a script using php-cgi 4.3 module. The script attempts to use the pcntl_fork() call but gets the error message "call to undefined function: pcntl_fork()" instead. Anyone know what's...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
0
by: David | last post by:
Hello, I'm trying to run a system call('ls' in this simple case) that is taking quite a long. I would like to fork the system call into a child process and waits display the output of the call...
4
by: Thomas | last post by:
I'm having some issues with forking and defunct children. This is my code: #!/usr/bin/php <?php $socket = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr); /* * LISTEN FOR...
1
by: chri | last post by:
I've compiled php with the option --enable-pcntl but when i call the function "pcntl_fork()" i obtain the error: "Call to undefined function: pcntl_fork()" Where is the bug? Have i to modify...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.