$max_wait) break; } // 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"; flock($lock_mutex_fd, LOCK_UN); return 0; } print "Pre-work
\n"; ob_start(); // Start buffering data $got_lock = wait_for_semaphore(); if($got_lock){ print "Work!
\n"; sleep(1); // not intended as work simulation // usleep(rand(1, 1000000)); // 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_name
\n"; ?>