2016-01-06 77 views
1

我的项目是使用Laravel4和mongoDB创建的。 我使用laravel artisan创建了一个命令,并在Laravel中使用此命令php artisan taxi:checktrips进行检查。在Laravel运行此命令:laravel4中的PHP artisan命令运行错误

public function schedule(Schedulable $scheduler) 
{ 
    return $scheduler->everyMinutes(.06); 
} 

/** 
* Execute the console command. 
* 
* @return mixed 
*/ 
public function fire() 
{ 
    while (true) { 
     try { 
      sleep(2); 

      foreach ($this->redis->keys('trip_id*') as $key) { 

       $trip_id = explode('|', $key); 
       $trip_id = $trip_id[1]; 

       if ($this->driver->closest($trip_id)) { 
        echo 'Closest, Add trip_temp_id Redis'; 
        $this->redis->set('trip_temp_id|'.$trip_id, 
         (int) $this->redis->get($key)); 
        Log::importRedis('trip_temp_id|'.$trip_id, $trip_id); 
       } 
       echo "{$trip_id}, Deleted Redis"; 
       $this->redis->del($key); 
       Log::exportRedis($key, $trip_id); 
      } 

      foreach ($this->redis->keys('trip_temp_id*') as $key) { 

       $trip_id = explode('|', $key); 
       $trip_id = $trip_id[1]; 
       if (\Carbon\Carbon::now()->timestamp > (int) $this->redis->get($key)) { 
        echo 'Deleting Temp Redis'; 
        $this->redis->del($key); 
        Log::exportRedis($key, $trip_id); 
        $this->driver->rejectTrip($trip_id); 
       } 
      } 
     } catch (\Exception $e) { 
      Log::errorLog([ 
       'file' => $e->getFile(), 
       'line' => $e->getLine(), 
       'code' => $e->getCode(), 
       'message' => $e->getMessage(), 
       'trace' => $e->getTrace(), 
       'trace_string' => $e->getTraceAsString(), 
       'previous' => $e->getPrevious(), 
      ]); 
     } 
    } 
} 
} 

但是当我执行我显示:

[MongoException] 
zero-length keys are not allowed, did you use $ with double quotes? 

如何解决,要没有任何问题上运行?

回答

1

我认为你应该确保你在$trip_id有效的值。

例如你使用:

$trip_id = explode('|', $key); 
$trip_id = $trip_id[1]; 

你确定你应该使用索引1这里,而不是0

+0

如果我把'0'。你认为问题会解决? – Amirali

+0

@Amiraliroshanaei我真的不知道你在Redis中的确切位置,以及你在'$ trip_id'中得到的结果 - 你应该逐步验证你在$ trip_id中实际获得的数据是 –

+0

我使用'568cceddbc919a427e8b4764'这样的mongoid和在redis中:我的项目驱动程序存在于队列中,并且使用redis,我接近乘客 – Amirali

1

我认为你试图将""作为你的db中的一个键。

做一两件事: -

在你php.ini

集mongo.allow_empty_keys为true

link可能会帮助你。

+0

。我使用debian服务器,我进入'/ etc/php5/apache2/php.ini',然后我写了'set mongo.allow_empty_keys to true',之后我重新启动了我的apache服务。但是我得到了同样的错误 – Amirali

+0

如果你是一个ubuntu用户,然后编写这个命令来知道哪个php.ini文件被加载。 sudo php -i | grep'配置文件' –