用php中的ignore_user_abort实现计划任务
2009-04-21 17:28
786 查看
今天一不小心在php手册上发现了这个函数-ignore_user_abort,这个函数可以帮助我们实现像linux中的cron一样实现计划任务,下面一起来看下该如何来实现。
首先看下php手册对这个函数的解释
Sets whether a client disconnect should cause a script to be aborted.
也就是说无论客户端是否关闭浏览器,下面的程序都会执行.
再看下其参数
If not set, the function will only return the current setting.
这个函数接受一个参数,来决定是否启用[b]ignore_user_abort[/b]的功能。
再看其返回值:
这里说返回前一次的设置,并且是bool值得,经过我的测试,这个说法是不对的,返回的明明是int型的,不相信的话大家可以写一个php文件来测试下。
说了这么多了,到底该如何用php的这个函数实现计划任务呢?还跌借助另外一个函数,这个函数是set_time_limit,通过set_time_limit0)可以设置程序的执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去。在程序执行之前加上[b]ignore_user_abort[/b](1)和set_time_limit(0)即可以了,最终程序该如何写呢?给大家一个例子。
ignore_user_abort(); // run script in background
set_time_limit(0); // run script forever
$interval=60*15; // do every 15 minutes...
do{
// add the script that has to be ran every 15 minutes here
// ...
sleep($interval); // wait 15 minutes
}while(true);
?>
首先看下php手册对这个函数的解释
Description
int [b]ignore_user_abort[/b] ([ bool $setting ] )Sets whether a client disconnect should cause a script to be aborted.
也就是说无论客户端是否关闭浏览器,下面的程序都会执行.
再看下其参数
Parameters
settingIf not set, the function will only return the current setting.
这个函数接受一个参数,来决定是否启用[b]ignore_user_abort[/b]的功能。
再看其返回值:
Return Values
Returns the previous setting, as a boolean.这里说返回前一次的设置,并且是bool值得,经过我的测试,这个说法是不对的,返回的明明是int型的,不相信的话大家可以写一个php文件来测试下。
说了这么多了,到底该如何用php的这个函数实现计划任务呢?还跌借助另外一个函数,这个函数是set_time_limit,通过set_time_limit0)可以设置程序的执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去。在程序执行之前加上[b]ignore_user_abort[/b](1)和set_time_limit(0)即可以了,最终程序该如何写呢?给大家一个例子。
ignore_user_abort(); // run script in background
set_time_limit(0); // run script forever
$interval=60*15; // do every 15 minutes...
do{
// add the script that has to be ran every 15 minutes here
// ...
sleep($interval); // wait 15 minutes
}while(true);
?>
相关文章推荐
- php计划任务php中的ignore_user_abort实现计划任务
- php计划任务php中的ignore_user_abort实现计划任务
- php ignore_user_abort()实现计划任务功能,实现文件能够在浏览器关掉之后照样运行
- PHP:ignore_user_abort()+set_time_limit(0)+sleep($interval)实现计划任务
- php计划任务php中的ignore_user_abort实现计划任务
- php计划任务之ignore_user_abort函数实现方法
- PHP 函数 ignore_user_abort定时执行任务的实现
- PHP计划任务之关闭浏览器后仍然继续执行的函数 ignore_user_abort
- PHP 函数 ignore_user_abort定时执行任务的实现
- php计划任务之ignore_user_abort函数实现方法
- php计划任务之ignore_user_abort函数实现
- 用 ignore_user_abort函数实现php计划任务
- 用ignore_user_abort函数实现php计划任务
- PHP5定时任务ignore_user_abort 和crontab
- php计划任务的实现
- linux下使用crontab实现定时PHP计划任务失败的原因分析
- 支持windows与linux的php计划任务的实现方法
- php定时计划任务实现方法
- [转]php中使用ignore_user_abort()函数后,如何停止后台运行的程序?
- ignore_user_abort 用于客户端终端,php脚本还会继续执行