note 81665 added to function.flock

From: Date: Sun, 09 Mar 2008 07:59:01 +0000
Subject: note 81665 added to function.flock
Groups: php.notes 
Request: Send a blank email to php-notes+get-136854@lists.php.net to get a copy of this message
I made some tests with flock () features. I made them because I read on a lot of articles that flock () doesn't work as expected and doesn't block against another processes. I made the tests with all operation options: 2: shared lock (read mode) 3: exclusive lock (write mode) 5: shared lock (read mode), without blocking the script execution 6: exclusive lock (write mode), without blocking the script execution All of them worked perfect on windows xp and php 5.2.5 note: when I say "without blocking the script execution" means flock () tries to block and if it can't, it doesn't stay waiting to acquire the lock, the php script continues running, and yeah, in windows even! I tested with notepad too while the script had locked the file, to see what happened if I made a save on the locked file and... I can't, notepad alerted me: another proccess has the file locked! The code used is the following: <?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 ?> ---- Server IP: 200.6.154.201 Probable Submitter: 190.39.212.75 ---- Manual Page -- http://www.php.net/manual/en/function.flock.php Edit -- https://master.php.net/note/edit/81665 Del: integrated -- https://master.php.net/note/delete/81665/integrated Del: useless -- https://master.php.net/note/delete/81665/useless Del: bad code -- https://master.php.net/note/delete/81665/bad+code Del: spam -- https://master.php.net/note/delete/81665/spam Del: non-english -- https://master.php.net/note/delete/81665/non-english Del: in docs -- https://master.php.net/note/delete/81665/in+docs Del: other reasons-- https://master.php.net/note/delete/81665 Reject -- https://master.php.net/note/reject/81665 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136854) next »