2016-01-06 32 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'配置文件' –

相關問題