hello,
i have prepared a php file for visitcount. that creates a text file per
day. as soon as any user visits that page ,a counter is incremented. but on
my site there is lots of trafic. that's why counter again starts with zero
. and file also written to null.b'coz multiple users(abt 1 to 10 lakh) can
visit page at same time.
so i want to know if code is right then what is the problem?
how can we solve this proble? is there any locking file mechanism in php?
code :[code=php]
$count_path = "../count_visit/".date("d-m-Y").".txt";
if(file_exists( $count_path))
{
$handle = fopen($count_pa th, 'r');
$read_count= fread($handle, filesize($count _path));
fclose($handle) ;
/* or used $read_count = file_get_conten ts($count_path) ;
*/
if($read_count <> '' )
{
$inc_count = (int)$read_coun t + 1;
$handle = fopen($count_pa th, 'w');
fwrite($handle, $inc_count);
fclose($handle) ;
}
}
else
{
// executes when any user visits first time
$handle = fopen($count_pa th, 'w');
fwrite($handle, '1' );
fclose($handle) ;
}[/code]
Plz solve this problem.
i have prepared a php file for visitcount. that creates a text file per
day. as soon as any user visits that page ,a counter is incremented. but on
my site there is lots of trafic. that's why counter again starts with zero
. and file also written to null.b'coz multiple users(abt 1 to 10 lakh) can
visit page at same time.
so i want to know if code is right then what is the problem?
how can we solve this proble? is there any locking file mechanism in php?
code :[code=php]
$count_path = "../count_visit/".date("d-m-Y").".txt";
if(file_exists( $count_path))
{
$handle = fopen($count_pa th, 'r');
$read_count= fread($handle, filesize($count _path));
fclose($handle) ;
/* or used $read_count = file_get_conten ts($count_path) ;
*/
if($read_count <> '' )
{
$inc_count = (int)$read_coun t + 1;
$handle = fopen($count_pa th, 'w');
fwrite($handle, $inc_count);
fclose($handle) ;
}
}
else
{
// executes when any user visits first time
$handle = fopen($count_pa th, 'w');
fwrite($handle, '1' );
fclose($handle) ;
}[/code]
Plz solve this problem.
Comment