Is there a way to make pcntl_fork work in WAMP? I need to develop a forking solution and test it locally.
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:
Unix/Linux:
exec('nohup php yourscript.php > /dev/null 2>&1 &');
Windows;
$com = new Com('WScript.shell');
$com->run('php yourscript.php', 10, false);
For documentation on the arguments, see: http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.85).aspx
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;
}
}
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: