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. -- --- Contact info: Skype: parham-d MSN: fire_lizard16 at hotmail dot com email: parham90 at GMail dot com "Ollisso" <ollisso@xxxxxxxxxx> wrote in message news:op.ux03zprl48vuyn@xxxxxxxxxxxxxxx > On Sun, 02 Aug 2009 07:11:27 +0300, "Parham Doustdar" <parham90@xxxxxxxxx> > wrote: > >> Dear Ollisso, >> I tried it with FLock() but it still didn't work. This is what I did: >> [code] >> $fp = fopen($f, "r"); >> $count =fgets($fp, 1024); >> fclose($fp); >> $fw = fopen($f, "w"); >> while (!flock($fw, LOCK_EX)) >> sleep(1); >> $cnew = $count + 1; >> $countnew = fputs($fw, $count + 1); >> flock($fw, LOCK_UN); >> fclose($fw); >> [/code] >> >> Am I doing anything wrong here? >> Thanks! > Hello, > > Actually you should do something like this (according to manual) > > $f=fopen("file", "r+"); > while(!flock($f, LOCK_EX)) sleep(1); > $count = fgets($f,1024); > ftruncate($f, 0); > fwrite($f, $count+1); > fclose($f); > > Problem in your case: first time you open file for reading, but you don't > flock it, so it can read non-writen file. > > > > > -- > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php