Home > Backend Development > PHP Tutorial > Parse PHP to implement multi-process parallel execution of scripts_PHP tutorial

Parse PHP to implement multi-process parallel execution of scripts_PHP tutorial

WBOY
Release: 2016-07-21 15:06:12
Original
814 people have browsed it

Since the PHP process does not support multi-threading, for convenience and performance improvement in some scenarios, you can use PHP to implement multiple processes to make up for this shortcoming:

Copy code 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){ //Parent process processing logic
pcntl_wait($status,WNOHANG);
}
else{ //Child process processing logic
pcntl_exec('/usr/local/bin/php',$cmd);
}
}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327644.htmlTechArticleSince the PHP process does not support multi-threading, in some scenarios for convenience and performance improvement, you can use PHP to implement multiple threads. Process to make up for this deficiency: Copy the code as follows: #!/usr/bin/...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template