How to enable fork (multi-processing) support in PHP?

Hello!

I can’t figure out how to run the following code to fork processes.

<?php
$pid = pcntl_fork();
if ($pid == -1) {
    echo 'Fork error.';
}
elseif ($pid) {
    echo 'Parent process.';
}
else {
    echo 'Children process.';
}
?>

The operating system is Mac OS X Lion Server, PHP version 5.3.6. I run the script from the terminal and this is what it gives:

alt text

I understand that my script runs without pcntl support, but I don’t understand how to do it.


Answer 1, authority 100%

You need to build php with this “–enable-pcntl”


Answer 2, authority 100%

You need to build PHP with pcntl support. For MacPorts (not quite hardcore by hand with ./configure --enable-pcntl && make && sudo make install) they write this:

sudo port selfupdate
sudo port update outdated
sudo port install php5-pcntl

(Whether they write the truth or not – I don’t know, OS X is not at hand, and I used it one and a half times in my life. How about not with MacPorts, but, say, with Homebrew – xs, you have to google, sorry. )