PHP Multi-Process Lab notes

Source: Internet
Author: User

<?phpfunction totalcount () {   $pdo  = pdo_mysql::getinstance ();   $params  = [' where '  => [' 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;&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;ELSE&NBSP;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

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


This article is from the "Old Cannon" blog, please be sure to keep this source http://joelemma.blog.51cto.com/11189330/1789211

PHP Multi-Process Lab notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.