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
-
-
CREATE TABLE IF NOT EXISTS `sessions` (
-
`sess_id` varchar(64) NOT NULL,
-
`sess_data` text NOT NULL,
-
`sess_time` int(11) NOT NULL,
-
KEY `sess_id` (`sess_id`)
-
) 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:
-
all:
-
sessions_db:
-
class: sfPropelDatabase
-
param:
-
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:
-
storage:
-
class: sfMySQLSessionStorage
-
param:
-
db_table: sessions # Name of the table storing the sessions
-
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: