I want to insure that there are no race conditions introduced by using a custom PHP error handler. To that end I want to know if I can rely on error_log() or if I need to use some other file-locking method to insure errors are logged correctly.
How does the default PHP error handler work? Is it safe from race conditions?
For example, do I have to lock the file (which might cause errors to be lost in this simple version)
function log_error($message)
{
if(! $fp = @fopen('/path/to/error.log', 'a'))
{
return FALSE;
}
flock($fp, LOCK_EX);
fwrite($fp, $message);
flock($fp, LOCK_UN);
fclose($fp);
return TRUE;
}
or can I just call error_log?
error_log($message, 0);