pcntl_fork questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawnmoth

    pcntl_fork questions

    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 :)
  • Kevin Thorpe

    #2
    Re: pcntl_fork questions

    yawnmoth wrote:
    [color=blue]
    > 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 :)[/color]

    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
    }

    ?>

    Comment

    • yawnmoth

      #3
      Re: pcntl_fork questions

      Kevin Thorpe <kevin@pricetra k.com> wrote in message news:<406bebd3$ 0$8577$afc38c87 @news.easynet.c o.uk>...
      <snip>
      [color=blue]
      >
      > 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
      > }
      >
      > ?>[/color]

      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?

      Comment

      Working...