From my age old php days (years ago) I slightly remember that I had big trouble with creating a log file in PHP. At random times, the file suddenly was plain blank (empty). I used something pretty close to this:
$myFile = "myFile.txt";
$fh = fopen($myFile, 'a');
$str = "New Entry...\n";
fwrite($fh, $str);
fclose($fh);
Is that really a safe way to work with a error log file when there are like 500 users at the same time executing PHP scripts (by surfing the website)? Lets assume there’s a really bad bug that causes every page view to produce an error log. That poor myFile.txt is then accessed like 100 times per second. I feel that this won’t work. I hope I’m wrong.
How would you do that?
http://de.php.net/manual/en/function.file-put-contents.php with FILE_APPEND
and LOCK_EXAlternatively http://de.php.net/manual/en/function.error-log.php