search
Homephp教程php手册PHP计划任务之关闭浏览器后仍然继续执行的函数

通过使用ignore_user_abort函数的特性,实现PHP计划任务,需要的朋友可以参考下。

备忘一下这个函数:
函数名称:ignore_user_abort
本函数配置或取得使用端连接中断后,香港服务器,PHP 程序是否仍继续执行。默认值为中断连接后就停止执行。在 PHP 配置文件中 (php3.ini/php.ini) 的 ignore_user_abort 选项就是配置处。本功能在 PHP 3.0.7 版之后才开始提供。
官方说明:


使用方法:

复制代码 代码如下:


ignore_user_abort(true); //即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.


这样就可以实现计划任务效果了.但是还是要客户端访问程序才行.
比如说在生成静态页面、采集的时候,免备案空间,香港服务器租用,不需要在等待了。关掉浏览器吧。
例子:

复制代码 代码如下:


//test
set_time_limit(0);
ignore_user_abort(true);
$i = 0 ;
while($i ++ file_put_contents($i.'.php' , $i);
sleep(3);
}


用ignore_user_abort函数实现php计划任务

复制代码 代码如下:


ignore_user_abort(true);
set_time_limit(0);
while(1) {
  $fp = fopen('time_task.txt',"a+");
  $str = date("Y-m-d h:i:s")."\n\r";
  fwrite($fp,$str);
  fclose($fp);
  sleep(5); //半小时执行一次
}
?>

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools