Home  >  Article  >  Backend Development  >  怎么在到达每天的00:00时自动执行一次PHP代码

怎么在到达每天的00:00时自动执行一次PHP代码

WBOY
WBOYOriginal
2016-06-13 12:10:51977browse

如何在到达每天的00:00时自动执行一次PHP代码?
RT
------解决思路----------------------
在服务器上设置定时任务
------解决思路----------------------
使用系統crontab,參考
http://blog.csdn.net/fdipzone/article/details/7263361
------解决思路----------------------
如何在到达每天的00:00时自动执行一次PHP代码?
使用计划任务
------解决思路----------------------
计划任务。。。。
------解决思路----------------------
00 00 * * * /usr/bin/php -f /home/wwwroot/default/test/test.php
------解决思路----------------------
做一个bat文件,里面使用schtasks 系统命令执行你要定时执行的php文件代码,点击该bat文件就能执行,不过你也可以在计算机的系统任务里面添加任务
------解决思路----------------------
ignore_user_abort(); //即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.
set_time_limit(0); // 执行时间为无限制,php默认执行时间是30秒,可以让程序无限制的执行下去
$time_year=date('Y',time());
if ($time_year%4==0 && ($time_year%100!=0 
------解决思路----------------------
 $time_year%400==0))
{
$days=366;
}
else
{
$days=365;
}
$interval=$days*24*60*60; // 每隔一年运行一次
do{
   
    //这里可输入您要执行的代码

sleep($interval);

}while(true);

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