Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
The session data stored by the application in the cookie exceeds 4Kb
  • Afternoon, I got this error on my logs. "The session data stored by the application in the cookie exceeds 4Kb". This is my code. http://bin.fuelphp.com/~J5. I try to follow from this furom but it's not working. http://fuelphp.com/forums/discussion/9705 can someone help me. I also ask some help from others but still got no solution. It says that I should not use session for emails. I want to send an email but when sending too much words, I got this error. This is an existing code, I have no idea how to replace codes by not using sessions.
  • There is a limit to how large a HTTP header can become (and a cookie is an HTTP header entry), which is dictated by the browser.

    To avoid your application weirdly crashing, Fuel checks if the size doesn't exceed 4Kb, which is a common cross-browser size.

    Reduce the amount of data you store in your session, or switch to a session store that doesn't have this size limitation (= all other session stores Fuel supports).
  • I got it, but between 'cookie', 'db', 'memcached', 'redis' and 'file'. What would I use? Do I need to change the codes if I change the session driver?
  • HarroHarro
    Accepted Answer
    In general, use 'cookie' only if you don't have any backend storage (for example you're on a two-bit shared host with a slow db) or you have very little to store.

    As to 'db', 'memcached', 'redis' or 'file', it depends what you have available, and what your requirements are.

    'db' and 'file' are persistent, 'memcached' isn't, 'redis' it depends on your config. 'memcached' is faster than the others, but might need a lot of memory if you have a lot of users. Usually, 'db' and 'file' can always be used, 'memcached' or 'redis' might not be installed.

    And in general, 'db' I/O tends to be a bit more efficient, especially in garbage collection, than 'file'.

    And no, the selection of session backend is completely transparent for your application, all you need to do is switch drivers in your session.php config file, and perhaps alter some driver depend settings.
  • Okay thanks Mr. Harron, I'll try 'db'.
  • Don't forget  to create the session table, there's a task to create it for you:

    php oil r session:create
  • It works. Thanks Harro. I can now send email any size I want. Thanks
  • Mr. Harro, I can now send emails. But sometimes this erroro occur. "Failed sending email in C:\xampp\htdocs\wewewewwe\fuel\packages\email\classes\email\driver\mail.php on line 33". This only appear around 1 out of my 100 testings. May I ask what are the reason why this error occur? I'm still bother why this happens even it only occur around 10% of my testings.
  • You are using the mail driver, which uses the PHP function mail() to send out email. You get this error if this function returns false. Under what conditions that happens, I don't really know.

    I personally tend to avoid this driver, and use the SMTP driver to deliver the mail (to localhost if you have a local MTA on your server), it is much more stable.

    Note that it also supports pipelining, a feature which when enabled keeps the connection open when you want to send multiple emails in a loop, which is faster and much more efficient than using mail().

    If you really want to send out bulk email, I suggest using an external provider that handles high-volume better than any local mail server.
  • Okay thanks Mr. Verton. I'm actually going to upload my mail function to real site and send out emails to more than 200 users. So I need to change my driver? If so, what could I use?
  • As said, I usually use an external service for bulk mail, but I don't really consider 200 emails bulk.

    Assuming your production server can send out email (either via a  mail server of your provider, or using a mailserver running on the server itself (like sendmail or postfix), I would use the SMTP driver.

    Create an email instance, call pipelining() to enable multiple email pipelining, and run your emails in a foreach loop, using that same email instance.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion