Session storage and FTP wrappers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Session storage and FTP wrappers

Post by alex.barylski »

I'm curious, assume you had a web application spread across several remote servers, how does one centralize the session storage so the PHP script on server A knows to lookup sessions stored on server Z. Likewise server B should lookup sessions on server Z as well.

I see two possible solutions:

1) Override the default storage mechianisms (session_set_save_handler) and store the data on the remote server - PITA
2) Possibly set the storage path with an ftp:// wrapper - much easier :D

Has anyone ever tried the latter - is there a way to configure PHP so that it allows ftp:// wrappers inside it's own INI file???

Cheers :)
User avatar
hawkenterprises
Forum Commoner
Posts: 54
Joined: Thu Feb 28, 2008 9:56 pm
Location: gresham,oregon
Contact:

Re: Session storage and FTP wrappers

Post by hawkenterprises »

No that is actually a built in security *feature*. You can't spread sessions across domain names to help prevent session hijacking. I'm sure there is a package hack but I would recommend just creating your own session system it's actually fairly easy to do.

Just use the same idea as the file save handle, just write a routine to load and save a file on a central server. That file contains all your session information. Thus you just created a central session system without using PHP's built-in ones.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Session storage and FTP wrappers

Post by Kieran Huggins »

I think Hockey's looking for more of a load-balancing type of setup, not cross-domain sessions.

Either way, FTP would kill your performance. Just watch the activity log in an FTP program sometime, it's sloooooow. Can you imagine reading and writing to that on every request? Ugh.

The answer? Use DB session storage: http://www.devshed.com/c/a/PHP/Storing- ... a-Database

Fast, cross-platform, and easy to set up! If the article doesn't already advocate this (it was the first result on Google, it might be total crap) I'd recommend using a HEAP table for sessions. HEAP (or sometimes called MEMORY) tables are kept in memory, and thus will perform better whilst not killing the rest of your DB server.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Session storage and FTP wrappers

Post by alex.barylski »

Ick...I was afraid I would have to go with the 'more work' option. :P

Ah well...figured I'd ask just incase.
Post Reply