PHP计划任务执行函数
ignore_user_abort
函数设置与客户机断开是否会终止脚本的执行。
本函数返回 user-abort 设置的之前的值(一个布尔值)。
官方说明:http://cn2.php.net/manual/en/function.ignore-user-abort.php
语法
ignore_user_abort(setting)
参数 | 描述 |
---|---|
setting |
可选。如果设置为 true,则忽略与用户的断开,如果设置为 false,会导致脚本停止运行。 如果未设置该参数,会返回当前的设置。 |
提示和注释
注释:PHP 不会检测到用户是否已断开连接,直到尝试向客户机发送信息为止。简单地使用 echo 语句无法确保信息发送,参阅 flush() 函数。
<?php // Ignore user aborts and allow the script // to run forever ignore_user_abort(true); set_time_limit(0); echo 'Testing connection handling in PHP'; // Run a pointless loop that sometime // hopefully will make us click away from // page or click the "Stop" button. while(1) { // Did the connection fail? if(connection_status() != CONNECTION_NORMAL) { break; } // Sleep for 10 seconds sleep(10); } // If this is reached, then the 'break' // was triggered from inside the while loop // So here we can log, or perform any other tasks // we need without actually being dependent on the // browser. ?>
Tiwer