got_lock){ // Got lock! Lets return to work return 1; } } // None of the locks where available, so let's sleep on it. sleep($sleep_time); } // Oops. No lock before timeout. Something is probably wrong. // mail("wikidown@wikipedia.org", "Lock timeout", "Seems like something got stuck?"); // print "Sorry, try again later"; return 0; } print "Pre-work
\n"; ob_start(); // Start buffering data $got_lock = wait_for_semaphore(); if($got_lock){ print "Work!
\n"; sleep(2); // Data is generated here } else { print "Oops! Failed to find a lock before timeout
\n"; } release_semaphore(); ob_flush(); // Data is sent to the client, without holding any locks print "Post work
\n"; print "Lock used was: $lock"; ?>