<?php
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_user_abort(); // 即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.
set_time_limit(0); // 执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去
$interval=20; // 时间间隔 单位 秒
$key_file="key.txt"; // 配置文件
if (isset($_GET['s']))
{
if ($_GET['s']=="0"){ // 停止工作,但不退出
$s="false";
echo "Function is off";
}
elseif ($_GET['s']=="1"){ // 工作
$s="true";
echo "Function is on";
}
elseif ($_GET['s']=="2"){ // 退出
$s="die";
echo "Function exited";
}
else
die("Err 0:stop working 1:working 2:exit"); $string = "<?php\n return \"".$s."\";\n?>";
write_inc($key_file,$string,true);
exit();
}
if(file_exists($key_file)){
do{
$mkey = include $key_file;
if ($mkey=="true"){ // 如果工作
///////////////////// 工作区间 //////////////////////////////////
$showtime=date("Y-m-d H:i:s");
$fp = fopen('func.txt','a');
fwrite($fp,$showtime."\n");
fclose($fp);
///////////////////////////////////////////////////////////////////
}
elseif ($mkey=="die"){ // 如果退出
die("I am dying!");
}
sleep($interval); // 等待$interval分钟
}while(true);
}
else
die($key_file." doesn't exist !");
function write_inc($path,$strings,$type=false)
{
$path=dirname(__FILE__)."/".$path;
if ($type==false)
file_put_contents($path,$strings,FILE_APPEND);
else
file_put_contents($path,$strings);
}
?>

  

最新文章

  1. tomcat启动的了,但是加载项目失败
  2. leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java
  3. $(document).ready()方法和window.onload区别
  4. 虚拟机安装Ubuntu到U盘
  5. IKONS – 赞!264 款手工打造的免费矢量图标
  6. 文件属性之setuid位
  7. 看懂理解 keyboard中 , navigation的设置: 切换工作区和移动窗口到不同的工作区.
  8. css实现红十字会图标
  9. [Twisted] transport和protocol解耦
  10. JavaScript 资源装备
  11. LTE发射机ACLR性能的测量技术
  12. [ mysql优化一 ] explain解释select语句
  13. python 文件打开小知识
  14. Spring Boot + Dubbo 可运行的例子源码-实现服务注册和远程调用
  15. Java类型转化报错
  16. 今年暑假不AC【贪心】
  17. 自动化运维工具sshd,expect,pssh,rsync详解
  18. .net framework , code first
  19. DWZ富客户端框架+DWZ简介及其使用+DWZ讨论组
  20. easyui按钮linkbutton 不可用(置灰)与 可用(取消置灰)

热门文章

  1. shell中常用的命令方法
  2. Windows下的git配置
  3. jQuery属性,方法操作
  4. java调用matlab函数
  5. Java中泛型在集合框架中的应用
  6. Java for LeetCode 155 Min Stack
  7. AU版有锁机的福利,704越狱彻底解决+86问题,完美IM/FT,重启不掉APN设置
  8. Android之多线程断点下载
  9. php 抽象类、接口和构析方法
  10. centos下安装五笔输入法的教程