0

Here is my problem.

I store array in Laravel session.

session(['array_cache' => $array]);

Array looks like this one:

array:59 [▼
  0 => array:18 [▼
    "id" => 2
    "type" => 3
    "partner_id" => 1
    "username" => "Pink11034519"
    "firstname" => "Jade"
    "lastname" => "Altenwerth"
    "age" => 18
    "gender" => "f"
    "email" => "brisa12@lubowitz.com"
    "mobile" => "406-361-6252 x4876"
    "rank_id" => 3
    "status" => 1
    "avatar" => ""
    "timezone" => "America/Anguilla"
    "available" => "7:00-11:30 | 13:00-17:00"
    "created_at" => "2018-08-28 02:56:26"
    "updated_at" => "2018-09-12 21:03:50"
    "pivot" => array:3 [▼
      "employee_id" => 1
      "storable_id" => 2
      "storable_type" => "Employee"
    ]
  ]
  1 => array:18 [▶]
  2 => array:18 [▶]
  3 => array:18 [▶]
  ....
  57 => array:18 [▶]
  58 => array:18 [▶]
]

When I store array like one above with more than 55 elements, session breaks and I get logged out.

If I decrease amount of data in subarrays, I am able to increase number of subarrays stored, before session breaks again.

So, it looks like size matters.

Are there any limits for array size stored in Laravel session?

Or maybe the problem is with Laravel auto serialization?

Anyone came across anything like this?

I appreciate some thoughts.


EDIT: Here's what happened.

As it happens project session is stored in DB.

Standard Laravel session table setup for 'payload' column is TEXT, which comes with: 65,535 chars.

Laravel serializes and base64 encodes session payload. That can quickly eat up allowed chars.

Decision as to changing storage to file is not up to me, so I changed TEXT to MEDIUMTEXT to increase storage capacity, although I am not too happy with potential size of stored string. I will write a memo and closely watch, how it works out.

Jeffz
  • 2,075
  • 5
  • 36
  • 51
  • You will get some details from https://stackoverflow.com/a/217443/1578380 – Chintan7027 Apr 24 '19 at 05:51
  • You better use session wisely. Instead of storing everything in session, you can lazy load the data if required from DB or something. If required use caching mechanism to achieve speed if most frequently data is being fetched. – Rahul Apr 24 '19 at 05:54
  • What's your `memory_limit` in PHP settings? – Tarasovych Apr 24 '19 at 06:05
  • Chintan - thank you; Tarasowych - memory limit: 2048M; Rahul: yes, it is for caching purposes, standard cache does not seem to be an option, as data is cached on user/session basis, but I consider looking that way. I think I consider putting this array to some well indexed database table to trade complex (thus expensive) query for a simple one. – Jeffz Apr 24 '19 at 06:34
  • I have no answer, but try changing `SESSION_DRIVER` (file, database, array...) to see if the problem remains. It can help you identify the source of the problem. – Clément Baconnier Apr 24 '19 at 06:56
  • @cbaconnier Thank you, I will try that. – Jeffz Apr 24 '19 at 07:19

1 Answers1

1

There is no limit in laravel session and you will get more idea about session from here

Mihir ajagia
  • 185
  • 1
  • 8