Re: Problem: Writing into Files?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 01 Aug 2009 08:20:23 +0300, "Parham Doustdar" <parham90@xxxxxxxxx> wrote:

Hi there,
I've written a counter for my blog, which keeps the count of visitors in a file. However, when the visitors get too many, it resets to zero. Why?

Here's the piece of code:

[code]
$f = $dir . '/view_counter' .EXT;
$fp = fopen($f, "r");
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, "w");
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
return $cnew;
[/code]

I'm thinking this is caused by two visitors visiting the page at the same time; but is there a way to fix it, perhaps the reading/writing parameter?

Thanks!


Check:
http://www.php.net/flock


--
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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux