8

Im building a laravel site and i have just found out that laravel sessions aren't shared with native php sessions.

At the moment i don't see any performance difference, but this site will get heavy traffic when complete. Is it best to stick with as much native PHP stuff where possible or is the laravel implementation for sessions more efficient than php?

Dan Hastings
  • 2,956
  • 6
  • 31
  • 62

1 Answers1

9

If you're using Laravel 4.0, it uses the native PHP session as its session driver by default, so the difference is negligible.

From Laravel 4.1 onwards, the new default session driver is called file, which stores session data in files on disk, and according to their 4.1 release notes, their sessions are now "leaner and faster":

Improved Session Engine

With this release, we're also introducing an entirely new session engine. Similar to the routing improvements, the new session layer is leaner and faster. We are no longer using Symfony's (and therefore PHP's) session handling facilities, and are using a custom solution that is simpler and easier to maintain.


Alternatively, you can use Redis or memcached to handle sessions - Laravel has drivers for both out of the box (note: for anything new, you should use Redis rather than memcached). You can consider this option if you have large session data (complex objects/data rather than a few strings or integers being stored) and/or a huge number of concurrent users (10,000+).

These drivers will store session data primarily in memory rather than on disk, so will be faster and more efficient, although the performance gain will more often than not be negligible unless you had a session-related performance bottleneck in the first place. If you do have such large session data that it's causing performance issues, then it may be pertinent to consider addressing this before looking to reconfigure your session engine.

Community
  • 1
  • 1
  • Thanks for this. I have memcached setup already, but i dont want to use it for basic user sessions as i want the sessions to be locked to each domain. I could append something to the variable name to make it domain specific, but standard php sessions suit my needs. I just had concerns that Laravel sessions might not scale very well. Im using Laravel 5 so id assume it would be. I think ill write the code in a way that allows me to easily change session types in future – Dan Hastings May 22 '15 at 12:18