Hello,
I have a page that loads and saves any errors that happen to a log variable.
Once the page has finished loading I want to write the log variable to a database if it has been used.
To do this I call an include function at the end of the page if the log has been used.
The log is often used to store problems that happened with connecting to a database, so if this is the problem it's likely that it won't be possible to write to the database at that moment so I want it to keep trying every minute until it writes to it even if the user has closed the page.
Also, as the log could be be updated quicker than it is written (and as it is constantly added to as a session variable, not written fresh each time) I want to cancel any previously running copies of the function also.
To achieve this I'm using this code:
<?php
//make sure people can't abort this script
flush();
ob_end_flush();
ignore_user_abort(true);
//tell any other running copies of f_log to abort and then wait for them to do so
$_SESSION['abort'] = true;
sleep (35);
//make sure no longer needing to abort
unset($_SESSION['abort']);
//write to log
$v_log = @makeslashes($log);
$q_updlog = "UPDATE logs SET log = '$v_log', used = '1' WHERE chatid = '$v_chatid'";
while (!$qr_updlog && !$_SESSION['abort']) {
$qr_updlog = mysql_query($q_updlog,$dbconnect);
sleep(30);
}
//make sure that the script is no longer going to abort
if (isset($_SESSION['abort'])) {
unset($_SESSION['abort']);
}
$_SESSION['log'] = $log;
?>
This code has several problems. Mainly that it takes a long time to show the page to the user and it is always saying it's loading for as long as I've been bothered to leave it running (quite a few minutes!).
So does anyone know what I'm doing wrong.. I'm guessing quite a bit because I'm not entirely sure I'm using this ignore_user_abort function right. The PHP manual seems a little thin on the ground witih info about it!
Thanks in advance,
Matt