<?php //輸出重定向到log文件 function echo_to_log($content){ global $html' target='_blank'>current_pid; $logfile = __FILE__ . $current_pid . '.log'; $fp = fopen($logfile, 'a+'); fwrite($fp, $content); fclose($fp);}ob_start('echo_to_log');//獲取當前進程pid$current_pid = getmypid();$fork_nums = 10; $total = 1000; for($i = 0; $i < $fork_nums; $i++){ $pid = pcntl_fork(); //等于0時,是子進程 if($pid == 0){ $current_pid = getmypid(); do_task($i); // 大于0時,是父進程,并且pid是產生的子進程PID } else if ($pid > 0){ }}//任務函數function do_task($task_num){ global $total; $start = $total / 10 * $task_num; $end = $total / 10 * ($task_num + 1); for(;$start<$end;$start++){ echo $task_num . " " . $start . "/n"; } //子進程執行完任務以后終止,當然你可以返回主進程的代碼部分做相關操作。 exit();}
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答