laravel4中的PHP artisan命令运行错误


PHP artisan command run error in laravel4

我的项目是用Laravel4和mongoDB创建的。我用laravel artisan创建了一个命令,并在laravel中使用这个命令php artisan taxi:checktrips来检查跳闸。该命令在Laravel运行:

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?

我如何才能修复它,使其运行时没有任何问题?

我认为您应该确保$trip_id中有有效的值。

例如,您使用:

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

您确定应该在此处使用索引1而不是0吗?

我认为您正试图将""保存为数据库中的密钥。

做一件事:-

在您的php.ini中,

将mongo.allow_empty_keys设置为真正的

希望这个链接能对你有所帮助。