Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using PHP sessions in Ruby

25 views
Skip to first unread message

Raphael Bauduin

unread,
Mar 4, 2005, 11:15:01 AM3/4/05
to
Hi,

As more people out there, most or all my web developments are done with Ruby (Ruby on Rails, keeping an eye on Nitro).
As I can't rewrite all existing PHP apps, I've looked at a way to use PHP session with Ruby, and I've written a class parsing a
PHP session (PHPSessionParser) that you initialise with the string being the PHP session data.
I'm storing PHP session in a postgresql database (http://www.csh.rit.edu/~jon/projects/pgsql_session_handler/) and I have written
a CGI session store to use the PHP sessions store in postgresql (called PHPDBIStore as it is using DBI, and not the postgresql driver
directly).

My employer agreed to let me publish it under the LGPL license. You can find the code at http://www.raphinou.com/php.rb

I'm not totally satisfied by the code design (if you look at the code, I'd like to not use the @working_str variable) but it's working for me.
You can store, modify, restore strings, arrays, hashes.

Feedback welcome. I'd like to know how you think this could be made better.

Thanks.

Raph

Raphael Bauduin

unread,
Mar 4, 2005, 11:20:47 AM3/4/05
to

Little addition:

to use it with rails, edit config/environment.rb and add these lines (adapting usernames, passwords, etc):

require 'php'
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:database_manager => CGI::Session::PHPDBIStore, :user => "dbuser", :password => 'dbpassword', :dbi_url => 'dbi:Pg:php_sessions:dbhost', :session_key => "PHPSESSID")

If with php you kept the default setting for the session key, you'll be reusing your php session immediately.

Raph

George Moschovitis

unread,
Mar 5, 2005, 2:42:30 AM3/5/05
to
Looks interesting, I will check this out.

-g.

0 new messages