php在linux后台执行

<?php
  ignore_user_abort();//后台运行
  ini_set('default_socket_timeout', -1);//socket不超时
  set_time_limit(0);
  $host = "127.0.0.1";
  $redis = new Redis();;
  if($redis->connect($host)){
      $redis->select(0);
      while(true){
          $msg = $redis->brPop('queue',0);
          $myfile = fopen("/log/message_queue.log", "a");
          if(!$myfile){
                $newFile = '/log/'.time().'.log';
                $myfile = fopen($newFile,"a");
          }
          $txt = json_encode($msg)."\n";
          fwrite($myfile, $txt);
      }
  }else{
      echo 'unable to connect';
  }




 

 

posted on 2017-08-14 10:28  会学习的猪  阅读(615)  评论(0编辑  收藏  举报

导航