繁体   English   中英

Laravel4中的PHP artisan命令运行错误

[英]PHP artisan command run error in laravel4

我的项目使用Laravel4和mongoDB创建。 我使用laravel artisan创建了一个命令,并在Laravel中使用此命令php artisan taxi:checktrips checktrips进行检查行程。 Laravel Runs中的以下命令:

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设置为true

希望此链接对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM