Help with PHP Process Control Functions

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

    Help with PHP Process Control Functions

    Hi,

    I have written a script that basically sends an email (using sockets). I
    want this script to be able to run multiple copies of itself so that it
    doesn't have to wait for one mail sending to finish before starting on the
    next. I understand that I need to use the PHP pcntl_ family of functions to
    control the processes, but am not sure where to start. There aren't many
    helpful articles on the internet about this topic! Any example code or help
    would be greatly appreciated.

    Thanks,
    Colin.


  • Tyrone Slothrop

    #2
    Re: Help with PHP Process Control Functions

    On Wed, 3 Dec 2003 13:03:42 -0000, "Colin Davis"
    <colin@ssintern et.co.uk> wrote:
    [color=blue]
    >Hi,
    >
    >I have written a script that basically sends an email (using sockets). I
    >want this script to be able to run multiple copies of itself so that it
    >doesn't have to wait for one mail sending to finish before starting on the
    >next. I understand that I need to use the PHP pcntl_ family of functions to
    >control the processes, but am not sure where to start. There aren't many
    >helpful articles on the internet about this topic! Any example code or help
    >would be greatly appreciated.
    >
    >Thanks,
    >Colin.
    >[/color]

    This sample has had a lot of code removed, but it may help
    understanding how this works: PHP must be compiled with pcntl.

    $pid = pcntl_fork();
    if ($pid)
    {
    // we are the parent
    sleep(1);
    $pid1 = pcntl_fork();
    if ($pid1)
    {
    sleep(1);
    $pid2 = pcntl_fork();
    if($pid2)
    {
    sleep(1);
    $pid3 = pcntl_fork();
    if($pid3)
    {
    sleep(1);
    }
    else
    {
    // we are in child
    sleep(1);
    # Do something here
    }
    }
    else
    {
    // we are in child
    sleep(1);
    # Do something here
    }
    }
    else
    {
    // we are in child
    sleep(1);
    # Do something here
    }

    }
    else
    {
    // we are the child
    sleep(1);
    # Do something here
    }

    Comment

    • Manuel Lemos

      #3
      Re: Help with PHP Process Control Functions

      Hello,

      On 12/03/2003 11:03 AM, Colin Davis wrote:[color=blue]
      > I have written a script that basically sends an email (using sockets). I
      > want this script to be able to run multiple copies of itself so that it
      > doesn't have to wait for one mail sending to finish before starting on the
      > next. I understand that I need to use the PHP pcntl_ family of functions to
      > control the processes, but am not sure where to start. There aren't many
      > helpful articles on the internet about this topic! Any example code or help
      > would be greatly appreciated.[/color]

      You may want to try this PHP thread class:




      --

      Regards,
      Manuel Lemos

      Free ready to use OOP components written in PHP


      Comment

      Working...