Home > php教程 > php手册 > PHP多进程控制的实例

PHP多进程控制的实例

WBOY
Release: 2016-06-06 19:52:54
Original
1348 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 在网上看大一位网友写的PHP多进程控制的实例,分享个大家: declare(ticks=1); function sigHandler($signal) { echo "a child exited\n"; } pcntl_signal(SIGCHLD, sigHandler, false); ech

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  在网上看大一位网友写的PHP多进程控制的实例,分享个大家:

  declare(ticks=1);

  function sigHandler($signal)

  {

  echo "a child exited\n";

  }

  pcntl_signal(SIGCHLD, sigHandler, false);

  echo "this is " . posix_getpid() . PHP_EOL;

  for($i=0; $i

  {

  $pid = pcntl_fork();

  if($pid == -1)

  {

  echo 'fork failed ' . PHP_EOL;

  }

  else if($pid)

  {

  }

  else

  {

  $pid = posix_getpid();

  echo 'child ' . $pid . ' ' . time() . PHP_EOL;

  sleep(rand(2,5));

  echo 'child ' . $pid . ' done ' . time() . PHP_EOL;

  exit(0);

  }

  }

  do

  {

  $pid = pcntl_wait($status);

  echo 'child quit ' . $pid . PHP_EOL;

  }while($pid > 0);

  echo 'parent done' . PHP_EOL;

PHP多进程控制的实例

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template