This article provides a detailed analysis of PHP multi-process parallel execution scripts. For more information, see this article because php processes do not support multithreading, in some scenarios, you can use php to implement multi-process to make up for this deficiency for convenience and performance improvement:
The code is as follows:
#! /Usr/bin/env php
$ Cmds = array (
Array ('/apps/bin/launcher. php', 'charge/promotion_props_stat.php', 'mobile', 1 ),
Array ('/apps/bin/launcher. php', 'charge/promotion_props_stat.php', 'mobile', 2 ),
Array ('/apps/bin/launcher. php', 'charge/promotion_props_stat.php', 'click', 1 ),
Array ('/apps/bin/launcher. php', 'charge/promotion_props_stat.php', 'click', 2 ),
Array ('/apps/bin/launcher. php', 'charge/promotion_props_stat.php', 1 ),
Array ('/apps/bin/launcher. php', 'charge/promotion_props_stat.php', 2)
);
Foreach ($ cmds as $ cmd ){
$ Pid = pcntl_fork ();
If ($ pid =-1) {// process creation failed
Die ('fork child process failure! ');
}
Else if ($ pid) {// processing logic of the parent process
Pcntl_wait ($ status, WNOHANG );
}
Else {// sub-process processing logic
Pcntl_exec ('/usr/local/bin/php', $ cmd );
}
}