lsdwyl 发表于 2018-11-2 12:56:11

PHP多进程开发与Redis结合实践

public function post_json() {  $image = $_FILES['image'];
  $data = I();
  $images = $this->post_upload($image);
  $data['image'] = $images ? $images : '';
  if( count($data) ){
  $redis = new Redis();
  $data['creation_time'] = time();
  //把发过来的帖子存储redis
  $result = $redis->lpush('news_list', json_encode($data));
  //          $redis->lpush('news_list', json_encode($data));
  //          while (TRUE){
  //            if ($redis->lsize('news_list') > 0){
  //                  $info = $redis->rpop('news_list');
  //                  $info = json_decode($info, true);
  //                  $result = $this->_model->news_publish( $info );
  //            }else {
  //                  sleep(1);break;
  //            }
  //          }
  //          $redis->close();
  $data['creation_time'] = time();
  //          $result = $this->_model->news_publish( $data );
  if( $result < 1 ){//redis方式
  //          if( !$result ){//model方式
  $this->_data['data'] = '';
  $this->_data['error'] = true;
  $this->_data['message'] = L('_DATABASE_ERROR_');
  }else{//success
  $this->_data['data'] = $result;
  $this->_data['error'] = false;
  }
  }
  else{
  $this->_data['data'] = '';
  $this->_data['error'] = true;
  $this->_data['message'] = L('_Invalid_Parameters_');
  }
  $this->response($this->_data);
  }

页: [1]
查看完整版本: PHP多进程开发与Redis结合实践