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

kupcza's avatar

Session dissapear

Hi guys,

I've got some problem with disappearing session. I'm using some ajax stuff for saving data in background.

The app is e-shop, where you choose some t-shirts, on another step you choose print image and print color on t-shirs front side, back side, ....

I found out that this issue could be caused by sending many ajax requests at same time. I'm using Laravel 4.2

I've tried to use DB driver for sessions and sometimes i got "Integrity constraint violation: 1062 Duplicate entry, ""...." error

The project you can find here http://skoly.kirix.cz (It's czech project).

0 likes
8 replies
kupcza's avatar

Hi,

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'a3b3d54f04639e6bc64636b2c7308fe347f62e00' for key 'id' (SQL: insert into kirix_sessions (id, payload, last_activity) values (a3b3d54f04639e6bc64636b2c7308fe347f62e00, YTozOntzOjY6Il90b2tlbiI7czo0MDoiSTN2VDFRbkhHdG1nektYR011NWhkWTlSdk9xYVZick5CeExNSm1MTCI7czo5OiJfc2YyX21ldGEiO2E6Mzp7czoxOiJ1IjtpOjE0MDk4MTU3NzI7czoxOiJjIjtpOjE0MDk4MTU3NzI7czoxOiJsIjtzOjE6IjAiO31zOjU6ImZsYXNoIjthOjI6e3M6Mzoib2xkIjthOjA6e31zOjM6Im5ldyI7YTowOnt9fX0=, 1409815772))

I don't know how session update works, so I am not able to fix this.

thepsion5's avatar

I'm not positive, but it should only be inserting sessions when a new one is created, correct? Maybe a new session is being created for the AJAX request, and if enough ajax requests hit the server fast enough, two sessions end up being created with the same ID. Something like this:

  1. Request #1 is fired
  2. Request #2 is fired
  3. Request #1 hits the server, creates a new session with a "unique" ID
  4. Request #2 hits the server, creates a new session with the same ID because that session file doesn't exist on disk yet
  5. Request #1 saves the session to the file
  6. Request #2 saves the session to the file, overwriting Request #1's session data

With DB sessions, this would cause a constraint violation because it would be inserting a second session row with the same ID as the first. I'm not sure about the solution though. I would have thought the session would start when you first hit the page, not when the first AJAX request is fired.

kupcza's avatar

I used file driver, but this didn't help. I problem is with loosing all info from session.

Step 1 - add products to cart (gloudemans/shoppingcart) Step 2 - by clicking save heading image and then big image. Also print color. Step 3 - same as step 2 but with back side

Sometimes it's ok, but sometimes I loose session id (I think) and with this I'm loosing all data. If you have better idea to store this printing attr (color, images, font, ...). Should I create order with this in 1st step? And just updating model? (Session will be used for cart and order_id)

bashy's avatar

Sounds like something in your PHP settings. Sessions shouldn't be re-created like that.

Take a look at the expire time in settings as it looks like it expires straight away

1 like
kupcza's avatar

Well, in my config, I've got 12hours, but expire_on_close set to TRUE. So now, I tried to set it to FALSE. I'll see, if it helped.

But thanks for idea.

kupcza's avatar

@winterwind I fixed this by setting correct expiration time and expire on close to false. But I didn't try it on L5.1

Please or to participate in this conversation.