简体   繁体   English

Laravel4中的PHP artisan命令运行错误

[英]PHP artisan command run error in laravel4

My project created with Laravel4 and mongoDB. 我的项目使用Laravel4和mongoDB创建。 I created an command with laravel artisan and use this command php artisan taxi:checktrips in Laravel for check trips. 我使用laravel artisan创建了一个命令,并在Laravel中使用此命令php artisan taxi:checktrips checktrips进行检查行程。 this command in Laravel Runs : 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(),
            ]);
        }
    }
}
}

but when i I executed shows : 但是当我执行时显示:

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

how can i fix that to run without any problem? 我该如何解决该问题而没有任何问题?

I think you should make sure you have valid values in $trip_id . 我认为您应该确保$trip_id具有有效值。

For example you use: 例如,您使用:

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

Are you sure you should use index 1 here and not 0 ? 您确定要在此处使用索引1而不是0吗?

I think you are trying to save "" as a key in your db. 我认为您正在尝试将""作为键保存到数据库中。

Do one thing:- 做一件事:

In your php.ini , 在您的php.ini

set mongo.allow_empty_keys to true 将mongo.allow_empty_keys设置为true

May this link will help you. 希望此链接对您有所帮助。

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

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