1

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?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
bitcodr
  • 1,395
  • 5
  • 21
  • 44

2 Answers2

1

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?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • If I put `0` . you think The problem will be solved? – bitcodr Jan 06 '16 at 14:40
  • @Amiraliroshanaei I really don't know what you have exactly in Redis and what you get in `$trip_id` - you should verify step by step what data you are actually getting – Marcin Nabiałek Jan 06 '16 at 14:42
  • in $trip_id i take a mongoid like `568cceddbc919a427e8b4764` and in redis : my project drivers exist in queue and with redis i take closest driver to passenger – bitcodr Jan 06 '16 at 14:53
1

I think you are trying to save "" as a key in your db.

Do one thing:-

In your php.ini,

set mongo.allow_empty_keys to true

May this link will help you.

Community
  • 1
  • 1
Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42
  • ok . i use debian server and i go in `/etc/php5/apache2/php.ini` and I wrote `set mongo.allow_empty_keys to true` after that i restart my apache service .but i got same error – bitcodr Jan 06 '16 at 14:46
  • If you are a ubuntu user, then write this command to know which php.ini file is loaded. sudo php -i | grep 'Configuration File' – Ravi Hirani Jan 07 '16 at 06:17