7

Is there a way to make pcntl_fork work in WAMP? I need to develop a forking solution and test it locally.

StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
  • 1
    You could try to run/compile it under Cygwin, where pcntl is more likely to function. Else you could handicraft something via the w32api extension if you dare (and if that's still available). – mario Feb 02 '11 at 20:07

3 Answers3

10

No, it's not possible. The PCNTL extension requires *nix platforms.

Now, with that said, what are you trying to do, and can you solve it without forking...?

Edit: Some alternatives to launching background processes:

ircmaxell
  • 163,128
  • 34
  • 264
  • 314
  • 1
    I need to have concurrent processes running. I can implement using cron (and using the DB to manage the number of processes running). However, say I wanted 10 concurrent processes running, I would need the cron to call a particular script 10 times -- in 1 minute increments -- in order to get all 10 scripts running (meaning, it'll take a full 10 minutes before I get the desired number of concurrent scripts). Alternatively, I can have have "dummy" functions call the same script (e.g. foo_1 calls foo, foo_2 calls foo, etc.) and have the cron call foo_1, foo_2, etc. every minute. Seems kludgy. – StackOverflowNewbie Feb 02 '11 at 20:02
  • 1
    @Stack: Well, there's more than one way to launch background tasks. You could use `nohup` and `&` on linux to disconnect the processes, or a COM WScript: http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.85).aspx object to launch background tasks... – ircmaxell Feb 02 '11 at 20:09
  • I want a solution that works both on localhost and the actual server (to simplify testing). I'm posting pseudo code of my planned solution. It still suffers from that "warm up" problem I described earlier. – StackOverflowNewbie Feb 02 '11 at 21:31
0

This has already been answered but I thought I would add my 2p.

You can have pcntl-fork with php in windows using cygwin.

It's a real pain to install, but if like me you just want a php cli script to run, it's your best bet.

I got instructions from here:

PaulM
  • 3,281
  • 3
  • 28
  • 38
-1

pseudo-code solution:

while (TRUE)
{
   $process_limit = get_process_limit();
   $process_count = get_process_count();

   if process count < process limit:
   {
      // get_row returns a row (as an array) from the DB that needs to be processed
      $row = get_row();
      if($row === array())
      {
         // Nothing to process; sleep
         sleep(2);
      }
      else
      {
         // Process row
         process_count(+1);
         process_row($row);
         process_count(-1);
      }

   }
   elseif process count === process limit
   {
      // Do not add to the process
      exit;
   }
   elseif process count > process limit
   {
      // Means the process limit was decreased
      // Terminate this process instance
      process_count(-1);
      exit;
   }
}
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441