using PHP sessions in Ruby

  • Thread starter Raphael Bauduin
  • Start date
R

Raphael Bauduin

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
 
R

Raphael Bauduin

Raphael said:
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top