用户
 找回密码
 入住 CI 中国社区
搜索
查看: 7837|回复: 9
收起左侧

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

[复制链接]
发表于 2012-11-2 09:32:36 | 显示全部楼层 |阅读模式
如题,我现在正碰上这个问题。。。
下面的代码我已经测试过了,最多运行6次,也就是半小时就停止了。。
PHP复制代码
 
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);
 
复制代码
发表于 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了
发表于 2012-11-7 10:53:50 | 显示全部楼层
1000次请求执行1次 酱子,很多虚拟主机限制太多
发表于 2012-11-7 18:52:22 | 显示全部楼层
百度crontab,能满足定时需求
发表于 2012-11-9 12:56:24 | 显示全部楼层
虚拟主机,不适合做任务。考虑放弃吧同志。
发表于 2012-12-1 03:28:17 | 显示全部楼层
z4213489 发表于 2012-11-7 18:52
百度crontab,能满足定时需求

虚拟主机没办法用crontab, 就一个ftp和web环境, 连个bash都不给的
发表于 2012-12-1 12:54:01 | 显示全部楼层
一般空间商为了节约资源不会让你这么干的。使用前端将就用吧
发表于 2012-12-31 01:42:08 | 显示全部楼层
虚拟主机限制多啊~
发表于 2013-1-3 18:59:43 | 显示全部楼层
呵呵,这是我现在网站正在使用的循环..
PHP复制代码
 
    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);
   }
 
复制代码

本版积分规则