Home  >  Article  >  Backend Development  >  PHP multi-process parallel execution script code

PHP multi-process parallel execution script code

WBOY
WBOYOriginal
2016-07-25 08:58:371310browse
  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


Statement:
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