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
<?php
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
}
?>