Back to Home

Codeigniter - Removing Sessions in Memcached

memcached · session · php · codeigniter

Codeigniter - Removing Sessions in Memcached

    Good day, habrosociety!

    When it comes to optimizing a web application, the battle is for every request.
    Therefore, at last they got around to optimizing the work with sessions. Previously, everything was stored in the database:

    $config['sess_use_database'] = TRUE;

    Session settings can be called standard, with the exception of the table name.

    After repeatedly viewing the profiler, it was decided to put all the work with sessions into Memcached.
    What for? Yes, at least in order to get rid of unnecessary updates and selects when generating the page.

    What has been done? The MY_Session class was written , overriding the key methods of the standard class for working with sessions.

    Modified Methods:
    • sess_read ()
    • sess_write ()
    • sess_create ()
    • sess_update ()
    • sess_destroy ()

    The essence of the changes is only to check what we use - DBMS or Memcached, and, accordingly, where to get and where to write session data.

    Some clarifications - in my case, the option of sessions through memcached was not taken out into the general config, i.e. it starts to work when sess_use_database = FALSE

    The settings for connecting to memcached are made in the config file of the same name - config / memcached.php.

    Work with memcached-server occurs through a wrapper, designed as a model.

    All files can be taken here .

    Read Next