class Pipler{ function runProcess($params){ $fork_num = $params['max_process_count']; // n个子进程处理任务 for ($i = 0; $i < $fork_num; $i++){ $pid = pcntl_fork(); if ($pid == -1) { die(); } elseif ($pid) { // } else { $r = curl_get($params['curl_url']); print_r($r); exit; } } while (pcntl_waitpid(0, $status) != -1) { $status = pcntl_wexitstatus($status); } } } $pipler = new Pipler; $pipler->runProcess($params);
排它锁,且等待20秒,超时然后退出
* * * * * /usr/bin/flock -x -w 20 /usr/home/tmp.lock -c 'php /var/www/html/letter/pipler.php >> /var/www/html/letter/log/pipler.log'
排它锁,直接退出:
* * * * * /usr/bin/flock -xn /usr/home/tmp.lock -c 'php /var/www/html/letter/pipler.php >> /var/www/html/letter/log/pipler.log'