CodeIgniter Forums
fwrite() being screwy - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: fwrite() being screwy (/showthread.php?tid=27793)

Pages: 1 2


fwrite() being screwy - El Forum - 02-22-2010

[eluser]Kepler[/eluser]
One other thing to try in case you have 2 separate processes calling the same code:


Code:
$fp = fopen('./logs/somefile.php','ab');
flock($fp, LOCK_EX);
if (($counter = $this->session->userdata('counter')) === false)
{
    $counter = 0;
}
$msg = 'TEST'.$counter;    
fwrite($fp, $msg);
$this->session->set_userdata('counter', ($counter + 1));
flock($fp, LOCK_UN);
fclose($fp);

If you still see "TEST0TEST0", I have no clue. Otherwise you have 2 threads calling the same code segment and the debug backtrace should help you out.

best of luck.