PHP multi-process parallel execution script code

WBOY
Release: 2016-07-25 08:58:37
Original
1277 people have browsed it
  1. #!/usr/bin/env php

  2. /**
  3. * php multi-process
  4. * by bbs.it-home.org
  5. */
  6. $cmds=array(
  7. array('/app/test.php' ,'charge/pstat.php','mobile',1),
  8. array('/app/test.php','charge/pstat.php','mobile',2),
  9. array('/app/ test.php','charge/pstat.php','click',1),
  10. array('/app/test.php','charge/pstat.php','click',2),
  11. array( '/app/test.php','charge/pstat.php',1),
  12. array('/app/test.php','charge/pstat.php',2)
  13. );

  14. foreach($cmds as $cmd){

  15. $pid=pcntl_fork();
  16. if($pid==-1){ //Process creation failed
  17. die('fork child process failure!');
  18. }
  19. else if($pid){ //Parent process processing logic
  20. pcntl_wait($status,WNOHANG);
  21. }
  22. else{ //Child process processing logic
  23. pcntl_exec('/usr/local/bin/php', $cmd);
  24. }
  25. }
  26. ?>

Copy code


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!