Home > Backend Development > PHP Tutorial > php定时计划任务的小事例

php定时计划任务的小事例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:41:28
Original
867 people have browsed it

php定时计划任务的小例子
本文介绍下,php实现定时计划任务的小例子,供大家学习参考。
  
PHP定时计划任务需要两个文件。
1,jbxue.conf.php

<?php
//当为0时,关闭计划任务
return 1;
?>
Copy after login

2,jbxue.php
<?php
ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
$interval=60*3;// 每隔3分钟运行
$ii=0;
do{
$run = include 'jhrw.conf.php';
if(!$run) {
    file_put_contents("tasktest.txt","==计划任务已结束==\r\n",FILE_APPEND);
    die('Job has ended.');
}
 //此入放要执行的代码
 sleep($interval);// 等待3分钟
 $nowTime = date("Y-m-d H:m:s");
 $data="$ii>计划任务正在运行中...(运行状态:$run)  $nowTime\r\n";
 file_put_contents("tasktest.txt", $data,FILE_APPEND);
 $ii++;
}while(true);
//by www.jbxue.com
?>
Copy after login

主要改变jbxue.conf.php中return 0即可实现控制这个计划任务的关闭。
本文出处参考:http://www.jbxue.com/article/9501.html

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template