By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

pcntl_fork questions

P: n/a
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)
print "test;
if ($pid2)
print "test2";
if ($pid3)
print "test3";
?>

any ideas why it didn't work? any ideas as to what i should be doing,
instead? thanks :)
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yawnmoth wrote:
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)
print "test;
if ($pid2)
print "test2";
if ($pid3)
print "test3";
?>

any ideas why it didn't work? any ideas as to what i should be doing,
instead? thanks :)


Assuming things work the same as in perl......

When you call $pid=pcntl_fork() you end up with two versions of your
script running. The original script will have $pid set to the child
process id, the child will have $pid set to false. The example in the
documentation explains it.

<?php

$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} else if ($pid) {
// we are the parent
} else {
// we are the child
}

?>
Jul 17 '05 #2

P: n/a
Kevin Thorpe <ke***@pricetrak.com> wrote in message news:<40**********************@news.easynet.co.uk> ...
<snip>

Assuming things work the same as in perl......

When you call $pid=pcntl_fork() you end up with two versions of your
script running. The original script will have $pid set to the child
process id, the child will have $pid set to false. The example in the
documentation explains it.

<?php

$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} else if ($pid) {
// we are the parent
} else {
// we are the child
}

?>


that makes since...

on a related note, the php docs say not to use the process control
functions on a webserver... why would this be, and is there anything
i could do to alievate whatever negative consequence could happen as a
result?

the thing is... i want to write a script to test whether or not some
tcpip address is a public proxy. my plan is to have it do this by
attempting to use the tcpip address as such. however, i don't want to
have to do one after the other, because that'd take more time than i'd
want anyone to have to wait...

i'd like to do the connections simultaniously, if i can... i just
don't know exactly how... is using the process control functions
would be a bad idea, what else could i use?
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.