note 9624 deleted from function.flock by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 19:08:47 +0000 |
| Subject: | note 9624 deleted from function.flock by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22079@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.