Quantcast
Channel: LampJunkie.com - Everything related to Linux, PHP, MySQL, Apache, AJAX, Symfony and more
Viewing all articles
Browse latest Browse all 10

Store Symfony Sessions in Database with Propel

$
0
0

Previously, I wrote a post on how to store user sessions in a database using Doctrine. I figured that I would follow it up by writing this article to demonstrate how to do the same thing using Propel. The steps are pretty much similar, but with some slight variations.

Step1 – Create your sessions table

  1.  
  2. CREATE TABLE IF NOT EXISTS `sessions` (
  3. `sess_id` varchar(64) NOT NULL,
  4. `sess_data` text NOT NULL,
  5. `sess_time` int(11) NOT NULL,
  6. KEY `sess_id` (`sess_id`)
  7. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Step 2 – Edit /config/databases.yml

You need to make sure that you have a connection set up for the session database. So edit /config/databases.yml so it has something like the following:

  1. all:
  2.   sessions_db:
  3.     class:          sfPropelDatabase
  4.     param:
  5.       dsn:          mysql://my_user:my_password@localhost/my_sessions_db

Step 3 – Edit the app/config/factories.yml

You will need to let symfony know that you are going to be using the sfMySQLSessionStorage class to handle your session storage, so edit /app/config/factories.yml:

  1.   storage:
  2.     class: sfMySQLSessionStorage
  3.     param:
  4.       db_table: sessions           # Name of the table storing the sessions
  5.       database: sessions_db     # Name of the database connection to use

Finally, make sure to clear your cache and you should be all set!

Step 4 – Configure symfony session cleanup, etc.

Andy, from blog.t8d.de posted some additional findings and links on their blog about some settings that you will want to change within symfony and your php.ini to make sure that your application is performing the proper session cleanup.

Check out:

  1. http://robrosenbaum.com/php/howto-disable-session-timeout-in-symfony/
  2. http://redotheweb.com/2008/02/01/database-session-handling-and-garbage-collector/

Viewing all articles
Browse latest Browse all 10

Trending Articles