Home  >  Article  >  php教程  >  php中的ignore

php中的ignore

WBOY
WBOYOriginal
2016-06-06 19:52:11993browse

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 用php中的ignore_user_abort函数实现计划任务: 用php的ignore_user_abort函数可以帮助我们实现像linux中的crontab一样的计划任务,下面看一下是如何来实现的. 语法: 手册上的说明 Description int ign

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

    用php中的ignore_user_abort函数实现计划任务:

    用php的ignore_user_abort函数可以帮助我们实现像linux中的crontab一样的计划任务,下面看一下是如何来实现的.

    语法:

    手册上的说明

    Description

    int ignore_user_abort ([ bool $setting ] )

    Sets whether a client disconnect should cause a script to be aborted.

    也就是说无论客户端是否关闭浏览器,下面的程序都会执行.

    参数说明:

    Parameters

    setting

    If not set, the function will only return the current setting.

    这个函数接受一个参数,来决定是否启用ignore_user_abort的功能.

    返回值:

    Return Values

    Returns the previous setting, as a boolean.

    这里说返回前一次的设置,并且是bool值得,经过我的测试,这个说法是不对的,返回的明明是int型的,不相信的话大家可以写一个php文件来测试下.

    实现定时器的功能还需借助set_time_limit函数,通过set_time_limit(0)可以设置程序的执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去.在程序执行之前加上ignore_user_abort(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中的ignore

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn