note 88785 added to function.flock

From: Date: Sat, 07 Feb 2009 13:33:44 +0000
Subject: note 88785 added to function.flock
Groups: php.notes 
Request: Send a blank email to php-notes+get-150362@lists.php.net to get a copy of this message
I have made below script and I was suprised because it does NOT work! <?PHP $content = ""; $input = fopen ("lock_test.txt", "w"); if (flock ($input, 6) == true){ echo "in...<br/>"; $time=time(); while (time()<$time+5) { } echo "out...<br/>"; flock ($input, 3); } else echo "can't acquire block..."; fclose ($input); //sleep () was used to give myself enough time to switch to another browser window, //invoke the script again to guarantee parallelism and make the notepad test to see //if an error occurred with other proccess ?> This script is similar to Daniel Gandra's script, witch works well: <?PHP $content = ""; $input = fopen ("lock_test.txt", "w"); if (flock ($input, 6) == true){ echo "in...<br/>"; sleep (5); echo "out...<br/>"; flock ($input, 3); } else echo "can't acquire block..."; fclose ($input); //sleep () was used to give myself enough time to switch to another browser window, //invoke the script again to guarantee parallelism and make the notepad test to see //if an error occurred with other proccess ?> One difference using: $time=time(); while (time()<$time+5) { } instead: sleep (5); ---- Server IP: 82.177.164.100 Probable Submitter: 89.25.200.36 ---- Manual Page -- http://www.php.net/manual/en/function.flock.php Edit -- https://master.php.net/note/edit/88785 Del: integrated -- https://master.php.net/note/delete/88785/integrated Del: useless -- https://master.php.net/note/delete/88785/useless Del: bad code -- https://master.php.net/note/delete/88785/bad+code Del: spam -- https://master.php.net/note/delete/88785/spam Del: non-english -- https://master.php.net/note/delete/88785/non-english Del: in docs -- https://master.php.net/note/delete/88785/in+docs Del: other reasons-- https://master.php.net/note/delete/88785 Reject -- https://master.php.net/note/reject/88785 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150362) next »