to :xuzuning(唠叨)没发财,我还穷着呢,呵呵。我的意思不是这样的,看下面的这段话,我是从某一版手册中看到的: ============================================= carlos at fischerinformatica dot com dot br 31-Jan-2002 10:58 Very very useful! I was building a chat and I wanted my script to detect when the browser was closed, so the user could be deleted from the online_users table.<? echo str_repeat(" ",300); ignore_user_abort(true); //this way, the user can stop the output, but not the script. while (true) { echo "test<br>\n"; flush(); sleep(2); if (connection_status()!=0){ include ('dbconnect.inc'); $sql="delete from online_users where online_user=$user"; $sql_exec=pg_exec($vChatDB, $sql); die(); //kills the script } } ?> ================================================ 他意思好像应该是说,这个程序运行永不过期,只要用户不关闭页面,页面就在后台一直得跑,用户关闭浏览器的时候,是否停止正在跑得php,是靠ignore_user_abort(true);设置的,但是我我怎么设置它都还在后台跑,怎么设置都不停。我测试的时候是php4.4.*
一般基本的测试程序应写成这样
<?php
function foo() {
$s = 'connection_status '. connection_status();
file_put_contents('__.txt', $s);
}
register_shutdown_function('foo');
set_time_limit(10);
for($i=0; $i<100000000; $i++)
echo $i;
?>__.txt文件的内容将是
1、程序正常结束
connection_status 0
2、点击浏览器“停止”按钮
connection_status 1
3、超时
connection_status 2注意程序一定要有输出,否则ABORTED状态是检测不到的******你的程序中有set_time_limit(0);和while (true)
所以程序不会超时和自然结束而使用connection_status()的地方不对至于ignore_user_abort函数,因没有测试,不好乱说
connection_status 3
connection_aborted 1
这样的结果的:虽然点击了“停止”按钮,但程序仍然运行到超时<?php
function foo() {
$s = "\r\nconnection_status " . connection_status();
$s .= "\r\nconnection_aborted " . connection_aborted();
file_put_contents('__.txt', $s, FILE_APPEND);
}
register_shutdown_function('foo');file_put_contents('__.txt', '');ignore_user_abort(true);
set_time_limit(10);for($i=0; $i<100000000; $i++) {
echo $i;
// if(connection_aborted()) foo();
}
?>
=============================================
carlos at fischerinformatica dot com dot br
31-Jan-2002 10:58
Very very useful!
I was building a chat and I wanted my script to detect when the browser was closed, so the user could be deleted from the online_users table.<?
echo str_repeat(" ",300);
ignore_user_abort(true); //this way, the user can stop the output, but not the script.
while (true) {
echo "test<br>\n";
flush();
sleep(2);
if (connection_status()!=0){
include ('dbconnect.inc');
$sql="delete from online_users where online_user=$user";
$sql_exec=pg_exec($vChatDB, $sql);
die(); //kills the script
}
}
?>
================================================
他意思好像应该是说,这个程序运行永不过期,只要用户不关闭页面,页面就在后台一直得跑,用户关闭浏览器的时候,是否停止正在跑得php,是靠ignore_user_abort(true);设置的,但是我我怎么设置它都还在后台跑,怎么设置都不停。我测试的时候是php4.4.*
你的php是什么版本的?配置文件有没有改过什么特殊的配置?
phpini没改过啥,就加了一些常用扩展,还有程序超时时间改的很长