Hi everyone,
I want to know how to use connection_abort() function, because I want to know the time before clients click stop button or close the browser.
My server is server 2003 and php5. My code as following, but it can not work.
Please show me your code. Thanks for your help, look forward to hearing from you soon.
Michael
<?php
//set_time_limit(10);
//ignore_user_abort(0);
function log_error() {
global $str_time;
$status=connection_status();
if(connection_status()==2)//2 means timeout
{
$oF=fopen('Error.log', 'a');
$pid=getmypid();
$run_time=time()-$str_time;
$ip = getenv("REMOTE_ADDR");
$isp = gethostbyaddr($ip);
//$referer = getenv("HTTP_REFERER");
$message=sprintf("%-10,%-20s,%-10d,%-20s,%-20s,%-40s",
$status,
date('Y-m-d H:i:s', time()),
$pid,
$run_time,
$ip,
$isp);
fwrite($oF, sprintf("%s\n",$message));
fclose($oF);
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$to="mbao@lawdepot.com";
$subject="PHP Fault Error: time out";
mail($to, $subject, $message, $headers);
exit;
}
else
{
if(connection_aborted())// user disconnect
{
$oF=fopen('Error.log', 'a');
$pid=getmypid();
$run_time=time()-$str_time;
$ip = getenv("REMOTE_ADDR");
$isp = gethostbyaddr($ip);
//$referer = getenv("HTTP_REFERER");
$message=sprintf("%-10,%-20s,%-10d,%-20s,%-20s,%-40s",
$status,
date('Y-m-d H:i:s', $str_time),
$pid,
$run_time,
$ip,
$isp);
fwrite($oF, sprintf("%s\n",$message));
fclose($oF);
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$to="mbao@lawdepot.com";
$subject="User close the browser";
mail($to, $subject, $message, $headers);
exit;
}
}
}
register_shutdown_function("log_error");
$str_time=time();
?>
<html>
<body>
<?php
for($x=1;$x<=100000000;$x++){
echo $x."<br>";
} // should send information to browser
echo "finished!";
?>
</body>
</html>