note 98844 added to function.pcntl-fork
| From: | iulian at osu1 dot php dot net | Date: | Sat, 10 Jul 2010 18:58:38 +0000 |
| Subject: | note 98844 added to function.pcntl-fork | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170864@lists.php.net to get a copy of this message | ||
When using fork to run multiple children processes on a single job queue using mysql, I used
mysql_affected_rows() to prevent collisions between workers:
First I find a "free" job:
SELECT job_id FROM queue WHERE status="free"
Then I update the queue:
UPDATE queue SET worker_id={$worker_id} WHERE job_id={$job_id}
Then I see if the row was changed
if(mysql_affected_rows() == 0)
{
//the row hasn't changed, so it must mean that another worker has claimed the job, so I go back
to the "find a free job" query
}
else
{
//do the job
}
----
Server IP: 69.147.83.197
Probable Submitter: 86.126.108.170
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-fork.php
Edit -- https://master.php.net/note/edit/98844
Del: integrated -- https://master.php.net/note/delete/98844/integrated
Del: useless -- https://master.php.net/note/delete/98844/useless
Del: bad code -- https://master.php.net/note/delete/98844/bad+code
Del: spam -- https://master.php.net/note/delete/98844/spam
Del: non-english -- https://master.php.net/note/delete/98844/non-english
Del: in docs -- https://master.php.net/note/delete/98844/in+docs
Del: other reasons-- https://master.php.net/note/delete/98844
Reject -- https://master.php.net/note/reject/98844
Search -- https://master.php.net/manage/user-notes.php