note 63832 added to function.flock

From: Date: Sat, 01 Apr 2006 06:08:17 +0000
Subject: note 63832 added to function.flock
Groups: php.notes 
Request: Send a blank email to php-notes+get-107119@lists.php.net to get a copy of this message
dranger at export dash japan dot com 's suggestion is correct and useful. My purpose is just preventing any other process from disturbing the current process which is rewriting a "cache" file, and flock() itself can help me to achieve this. $fp = fopen( "test.txt", "ab" ); if( $fp && flock( $fp, LOCK_EX ) ) { ftruncate( $fp, 0 ); fwrite( $fp, $part_one ); sleep( 10 ); // for test purpose, assume the whole writing process takes 10 seconds fwrite( $fp, $part_two ); fclose( $fp ); } it works well, I open 3 browser windows to request this page, and the third one actually takes more than 20( about 26 ) seconds to finish. and the content of cache.txt is correct and up-to-time. tested under: 1, windows, apache2, php4.4.1 2, freebsd, apache, php4.2.3 ---- Server IP: 219.239.98.8 Probable Submitter: 202.120.52.84 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.flock.php Edit -- http://master.php.net/note/edit/63832 Del: integrated -- http://master.php.net/note/delete/63832/integrated Del: useless -- http://master.php.net/note/delete/63832/useless Del: bad code -- http://master.php.net/note/delete/63832/bad+code Del: spam -- http://master.php.net/note/delete/63832/spam Del: non-english -- http://master.php.net/note/delete/63832/non-english Del: in docs -- http://master.php.net/note/delete/63832/in+docs Del: other reasons-- http://master.php.net/note/delete/63832 Reject -- http://master.php.net/note/reject/63832 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107119) next »