xgdd1987 发表于 2012-11-2 09:32:36

求 虚拟主机php定时任务如何来做?

如题,我现在正碰上这个问题。。。
下面的代码我已经测试过了,最多运行6次,也就是半小时就停止了。。

ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
$interval=60*5;// 每隔5分钟运行
do{
date_default_timezone_set('Asia/Shanghai');
$fp   = fopen("test.txt", "a+");
$time=time();
$dt=date("Y-m-d H:i:s",$time);
echo $dt;
fwrite($fp,$dt. " 成功成功了!\n");
fclose($fp);
$stop=strtotime('2012-11-10');
if($time>$stop) die('process abort');
//这里是你要执行的代码
sleep($interval);//
}while(true);

Shengzhi 发表于 2012-11-2 11:25:34

尝试使用ignore_user_abort()

大道达人 发表于 2012-11-4 21:10:07

CI本身支持 CLI
你可以看下
http://cier.phpfogapp.com/index.php/docs/start/basic/chapter05
crontab就ok了

Just_alive 发表于 2012-11-7 10:53:50

1000次请求执行1次 酱子,很多虚拟主机限制太多

z4213489 发表于 2012-11-7 18:52:22

百度crontab,能满足定时需求

bluelomo 发表于 2012-11-9 12:56:24

虚拟主机,不适合做任务。考虑放弃吧同志。

=-= 发表于 2012-12-1 03:28:17

z4213489 发表于 2012-11-7 18:52 static/image/common/back.gif
百度crontab,能满足定时需求

虚拟主机没办法用crontab, 就一个ftp和web环境, 连个bash都不给的

太尉天上飞 发表于 2012-12-1 12:54:01

一般空间商为了节约资源不会让你这么干的。使用前端将就用吧

tcnxm23 发表于 2012-12-31 01:42:08

虚拟主机限制多啊~

273579540 发表于 2013-1-3 18:59:43

呵呵,这是我现在网站正在使用的循环..

    public function __construct(){
         parent::__construct();
      $this->load->library('crawler');
    }
   
   public function index(){
   include_once APPPATH.'controllers/it.php';
   include_once APPPATH.'controllers/movie.php';
   include_once APPPATH.'controllers/book.php';
   include_once APPPATH.'controllers/game.php';
   $it=new It();
   $movie=new Movie();
   $book=new Book();
   $game=new Game();
   ignore_user_abort(); //忽略用户操作
   set_time_limit(0); //不限制运行时间
    // $interval=60*60*6;//6个小时执行一次
   $interval=60*60*6;
   do{
      $it->index();
      $movie->index();
      $book->index();
      $game->index();
            sleep($interval);
   }while(true);
   }
页: [1]
查看完整版本: 求 虚拟主机php定时任务如何来做?