On Sun, 02 Aug 2009 13:14:42 +0300, "Parham Doustdar" <parha...@gmail.com>
wrote:

Now this one always sets the file to one for some reason. I'll reiterate
just in case there's been a misunderstanding on my part:
[code]
$fp = fopen($f, "r+");
while (!flock($fp, LOCK_EX))
sleep(1);
$count = fgets($fp,filesize($fp));
ftruncate($fp, 0);
fwrite($fp, ($count+1));
flock($fp, LOCK_UN);
fclose($fp);
Thanks a lot again for your help.


This will work:

$f      = 'file.txt';
$fp = fopen($f, "r+");
while (!flock($fp, LOCK_EX))
        sleep(1);
$count = intval(fread($fp,1024));
fseek($fp,0,SEEK_SET);
ftruncate($fp, 0);
fwrite($fp, ($count+1));
fclose($fp);

echo $count;

(first you should create file file.txt manually, only then it will work)

--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to