Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davidrushton's avatar

Help with sessions duplicate id?

I recently updated a project to use Laravel 5.2 and am having some sporadic exceptions like the following picked up by Sentry:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '403f212667d4940b3524a352f983cbe05057b035' for key 'sessions_id_unique' in /path/to/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:408
  • I use the database session driver
  • I've not modified the default session middleware or driver code
  • My database table is the default with a 255 varchar unique key for the sessions.id

My session.php looks like following

<?php

return [

    'driver' => env('SESSION_DRIVER', 'file'),

    'lifetime' => 120,

    'expire_on_close' => false,

    'encrypt' => false,

    'files' => storage_path('framework/sessions'),

    'connection' => null,

    'table' => 'sessions',

    'lottery' => [2, 100],

    'cookie' => 'worldwalking',

    'path' => '/',

    'domain' => null,

    'secure' => false,

    'http_only' => true,

];

If anyone has experienced this problem and fixed, or has any thoughts, I'd be very grateful for a heads up or any advice.

Thank in advance :)

0 likes
1 reply
davidrushton's avatar

Incase anyone else stumbles upon this, I've not experienced this in a few days.

One of the main changes I made was caching config using php artisan config:cache, after each deployment. I think I saw somewhere else that this might be related to the boot-time and therefore have an impact on the session.

Hope that helps.

Please or to participate in this conversation.