note 9624 added to flock

From: Date: Wed, 15 Nov 2000 20:06:23 +0000
Subject: note 9624 added to flock
Groups: php.notes 
Request: Send a blank email to php-notes+get-7722@lists.php.net to get a copy of this message
With an eye toeard reducing the time my app has a file locked, I came up with the following which doesn't require two fopen()'s: $fp=fopen("reqid","a+"); if ($fp !=0 && flock($fp,2) && fseek($fp,0)==0){ fscanf($fp,"%d",&$id); $id++; ftruncate($fp,0); fwrite($fp,$id); } fclose($fp); I'm not positive this is faster, but it seems cleaner to me. http://www.php.net/manual/function.flock.php

« previous php.notes (#7722) next »