php - fwrite saves same message multiple times -
i use fwrite in php log errors in logs.txt.
the problem when open db_errors.txt see message saved multiple times instead of once.
my fwrite code not inside loop, definately executed once. same think happended using third party logger classes.
if (!$result = mysqli_query($link, $query)){ $today = getdate(); $handle = fopen("logs/db_errors.txt", "a"); fwrite($handle, $today['mday'].'/'.$today['mon'].'/'.$today['year']." | ".mysqli_errno($link)." : ".mysqli_error($link)." | ".$query." \n"); fclose($handle); } this writes in 3 lines inside db_errors.txt same output.
11/4/2011 | 1054 : unknown column 'uids' in 'field list' | select uids users user_id=6 limit 1 11/4/2011 | 1054 : unknown column 'uids' in 'field list' | select uids users user_id=6 limit 1 11/4/2011 | 1054 : unknown column 'uids' in 'field list' | select uids users user_id=6 limit 1
my fwrite code not inside loop, definately executed once. same think happended using third party logger classes.
if someone else's code shows same behavior, have 1 possible root cause: code being called 3 times.
it's time get out debugger , add breakpoint code, step through happens after first call. undoubtedly lead source of later calls.
you might want consider adding full timestamp , microtime log instead of getdate. may make troubleshooting more effective proving there indeed 3 calls being made.
$time_plus_micro = date('y-m-d h:i:s') . ' ' . microtime(true) fwrite($handle, $time_plus_micro . " | ...";
Comments
Post a Comment