RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
php多进程实验笔记
 ['id' => ['>=' => 672600],]];
  $result = $pdo->count('Crawl_Receive_Task', $params);
  $pdo = null;
  return $result;
}
function selectCountList()
{
  $pdo = PDO_MySQL::getInstance();
  $conditions = array(
      'fields' => 'id,url,info_path',
      'where' => ['id' => ['>=' => 672600],]
  );
  $result = $pdo->getAll('Crawl_Receive_Task', $conditions);
  $pdo = null;
  return $result;
}

function update($data, $id)
{
  $pdo = PDO_MySQL::getInstance();
  $where = array(
      'where' => array(
          'id' => $id
      )
  );
  $result = $pdo->update('Crawl_Receive_Task', $where, $data);
  $pdo = null;
  return $result;
}


$t =  totalCount();
$list =  selectCountList();
$start=0;
$threads = 4;
while($start<$t){
  if($start == $t) break;
  for($i=$start;$i<$start+$threads;$i++){
    $pids[$i] = pcntl_fork();
    if($pids[$i]) {
      echo $pids[$i]."parent".PHP_EOL;
    }
    else if(!$pids[$i]) {
      echo getmypid()."--".$pids[$i]."--child".PHP_EOL;
      $result = Curl::request('GET',$list[$i]['info_path']);
      update(['add_time'=>date('Y-m-d H:i:s'),'test'=>$list[$i]['id']],$list[$i]['id']);
      echo $result."-----------------".PHP_EOL;
      exit();
    }
    usleep(100);
  }
  for($i=$start;$i<$start+$threads;$i++){
    pcntl_waitpid($pids[$i], $status, WUNTRACED);
    $status = pcntl_wexitstatus($status);
    echo "--------$status finished--------".PHP_EOL;
  }
  $start+=$threads;
}

  |-php-fpm,16784                                                      

定襄网站建设公司创新互联公司,定襄网站设计制作,有大型网站制作公司丰富经验。已为定襄上1000家提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的定襄做网站的公司定做!

  |   |-php-fpm,16817                                                                                              

  |   |-php-fpm,16821                                                                                              

  |   `-php-fpm,16822                                                                                              

  |   |       |-php,17984 132.php

  |   |       |   |-php,17987 132.php

  |   |       |   |   |-php,17992 132.php

  |   |       |   |   |   |-php,17994 132.php

  |   |       |   |   |   |   `-php,18000 132.php

  |   |       |   |   |   `-php,17997 132.php

  |   |       |   |   |-php,17995 132.php

  |   |       |   |   |   `-php,18001 132.php

  |   |       |   |   `-php,17998 132.php

  |   |       |   |-php,17988 132.php

  |   |       |   |   |-php,17993 132.php

  |   |       |   |   |   `-php,17999 132.php

  |   |       |   |   `-php,17996 132.php

  |   |       |   |-php,17989 132.php

  |   |       |   |   `-php,17990 132.php

  |   |       |   `-php,17991 132.php

  |           |-grep,18003 php

==============================================================

17984 1755

17987 17984

17988 17984

17989 17984

17991 17984

17992 17987

17995 17987

17998 17987

17993 17988

17996 17988

17990 17989

17994 17992

17997 17992

17999 17993

18000 17994

18001 17995


当前文章:php多进程实验笔记
标题路径:http://sczitong.cn/article/ghhgpe.html