I have a Macbook Pro running OSX Yosemite. I am trying to run a simple PHP script using pcntl_fork()
on the command line (command: php pcntl.php
):
<?php
$pid = pcntl_fork();
switch($pid) {
case -1:
print "Could not fork!\n";
exit;
case 0:
print "In child!\n";
break;
default:
print "In parent!\n";
}
?>
The response is this:
Fatal error: Call to undefined function pcntl_fork() in
/Users/grant/Desktop/test/pcntl.php on line 2
I've seen numerous articles that show you how to install pcntl if you are running mamp, but if you are simply using terminal, how would you go about installing pcntl? If this is not possible on the command line, is there something similar in PHP that does work?
In case of native CLI you should proceed the same way as in case of
MAMP
. The only difference is that you should add support to nativephp
and not toMAMP
's one.Yosemite
's php doesn't havepcntl
support. Following command returns no output:Verify your php version:
Download and build
pcntl
module:Copy module to extensions folder:
Edit
php.ini
configuration file:And add
extension=pcntl.so
line inDynamic Extensions
section, e.g.:Verify
pcntl
support again (support enabled this time):Running your test script: