Ad

PHP Artisan Command Run Error In Laravel4

My project created with Laravel4 and mongoDB. I created an command with laravel artisan and use this command php artisan taxi:checktrips in Laravel for check trips. this command in 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?

Ad

Answer

I think you should make sure you have valid values in $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?

Ad
source: stackoverflow.com
Ad