用PHP来模拟实现shell脚本(模拟计划定时任务)

 

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

set_time_limit(0);//执行时间为无限制,php默认的执行时间是30秒,通过

set_time_limit(0)可以让程序无限制的执行下去

$interval=60*60*12;     //60*60表示1小时  1小时*12表示12小时

$i = 1;

do{

    file_put_contents('/data/www/hostingtool.com/test/text.txt','第' .
    $i++ . '个12小时'.'\n',FILE_APPEND);

    sleep($interval);//等待时间

}while(true);

 

 

php手册中的贡献代码:

 

// php手册中的贡献代码:
// If you want to simulate a crontask you must call this script once and it will keep running forever (during server uptime) in the background while "doing something" every specified seconds (= $interval):
// 如果你想要模拟一个计划任务必须调用此脚本一次,它就会永远保持运行(在服务器正常运行期间)在后台做一些事情到永远,每过一个特殊的秒数 (=$interval)

ignore_user_abort(1); // 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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值