473,811 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_THR EADS;$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++) {
myVeryLongFunct ion();
};
exit($childs);
};
};
if ($pid) {
while ($childs>0) {
$cid=pcntl_wait pid(-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 1162

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

Similar topics

2
2528
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 = pcntl_fork(); $pid3 = pcntl_fork(); if ($pid1)
117
7278
by: Peter Olcott | last post by:
www.halting-problem.com
1
2615
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 script in php. I am thinking about having it invoked by xinetd instead of being a server running all the time. I looked at the source code of nanoweb, but couldn't really figure out how xinetd interacts with my script, in particular how it passes the...
3
10171
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 going on? I have Apache 2.0+, Php-cgi 4.3 Mandrake Linux 9.1. Here is my fork.php script: #!/usr/bin/php-cgi <?php
28
5228
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(); .... and then call the virtual method, why is it that the base class's method is called instead of the overridden method? How do I fix this if I don't know at runtime what the child class is? I'm using Activator.CreateInstance() to load the...
6
3818
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 is more that 1249 bytes, then the progress bar of the browser will move too slow and then displaying that the page not found!!!! If the message is less than or equal to 1249 then no problem.
0
1833
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 while it is running. Here is a piece of code: $pid = pcntl_fork(); for ($i = 1; $i <= 5; ++$i) {
4
5658
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 CONNECTIONS */ while(TRUE){
1
3616
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 php.ini too? If yes, how? Server configuration is: Apache2 2.2.3 and Debian 4. Thanks
0
9724
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.