0

I don't seem to be able to set a "large" values to a session variable. I tried setting a 1000 character piece of text and it's not being stored.

Session::put('key',$text);

This is also an issue when validating forms with lots of inputs. The values of the inputs don't necessarily need to be large to make it crash. If the form has lots of inputs and there is a validation error that needs to be propagated back to the view "->withInput()", all the input gets lost as well.

I tried with cookie and file session handlers and set session max size to 4KB and also 8KB.

Laravel 5.2.

joanfihu
  • 336
  • 2
  • 9

1 Answers1

3

That is a known issue. Create a php artisan make:migration change_sessions_table and add this:

public function up()
{
    Schema::table('sessions', function (Blueprint $table)
    {
        $table->longText('payload')->change();
    });
}

And run php artisan migrate, even on a production server.

A word of caution about the use of sessions in this way. If it is for inserting query results, after a while it may not be sufficient as your database grows. You will have to circumvent other ways. You could use the store cache for example.

Dimitri Mostrey
  • 2,302
  • 1
  • 12
  • 11
  • Shall I do this even if I don't use the database as a session handler? We use file and cookie handlers in local and memcached in production. – joanfihu Aug 13 '18 at 15:24
  • Oh, so your sessions are file based. So you don't need to do this as 'sessions' doesn't exist in your database. Do you immediately try to access the session (file)? If so, it could be the file is still being written. In the case of a form that is not possible. Honestly, I have no idea why this happens to you. Unless the memcached value can not hold big values. I can't help you with memcached. – Dimitri Mostrey Aug 13 '18 at 15:35
  • Yes I tried to access to the input at the next request but it should work fine as this is the default set up when using the form validator. It uses session to pass up old inputs. The issue happens with either: file, memcached and cookie as a session handler. Very strange! – joanfihu Aug 13 '18 at 15:40
  • I start to suspect a session setting. Lifetime maybe. Or the encrypted setting. Try to play around with the `config/session.php` file. Also shut down the lottery, especially on test servers `'lottery' => [0, 100],`. Shutting it down on a live server will create an overwhelming amount of session entries. So use this with caution. There is a reason it exists. – Dimitri Mostrey Aug 13 '18 at 15:52
  • Does the very same problem ocurr for file and memcache drivers, then? – alariva Aug 13 '18 at 15:58
  • If we speak about sessions and the settings. Yes. But this can be solved by using the .env file and creating unique settings for each server environment. SESSION_LOTTERY and things like that. Remember that on a prod server, the .env is only accessible during the boot process (all config/* files) and nowhere else. – Dimitri Mostrey Aug 13 '18 at 16:02