I know this is not proper error handling, but it is necessary to solve my problem. I am running a script that parses data in a loop over many hours, so I create a logs of what is happening in the script at various moments to ensure everything is being handled correctly. All my logs are saved in a different folder than the .php file. I was recording and logging tons of information. But, all the connecting to the log file was tremendously slowing down my program. Instead i have a global $write variable and I just append it. In order to speed up my program I just want to append my log file with $write, once at the end of each loop. The problem is that I set a max_execution_time for my program and if it dies before the loop is done, all my logs for that loop are lost. As part of my register_shutdown_function() I want to log $write.
Here's what I have:
register_shutdown_function( "fatal_handler");
function fatal_handler() {
global $file, $write;
$errfile = "unknown file";
$errstr = "shutdown";
$errno = E_CORE_ERROR;
$errline = 0;
$error = error_get_last();
if( $error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
file_put_contents($file, "\n\nFATAL ERROR\n\n", FILE_APPEND);
file_put_contents($file, $write, FILE_APPEND);
}
}
The problem is that I get this error message: Warning: file_put_contents(../../resultLogs/log.txt): failed to open stream: No such file or directory in C:\www\php\data_utils\program.php on line 64
Mind you $file works fine in the rest of the program... Help please!