Jump to content

How to hook in order to store session in database


raoul
 Share

Recommended Posts

Hi!

I'm currently discovering Process Wire and i may encounter a blocking problem, preventing me to use pw :

My server environnement doesn't allow me to store sessions in files, the only way to store sessions is in the database (clustered servers).

I'm wondering how can I hook properly the wire session class,

my options are:

- hook the wire session class

- hack the wire session class

- attempt to ignore the wire session class and use my existing session class, and just hook/replace the login method

- wait and pray? ( http://processwire.c...ts-of-sessions/ )

My level of OOP PHP is not so good

my first attempt to hook failed:

$this->session->addHookBefore('set', $this, 'set');

return this exception:

Error Exception: Method Session::set is not hookable (in /htdocs/..../wire/core/Wire.php line 371)

any advices welcome :)

Link to comment
Share on other sites

Hi, Raoul.

Not sure it's the right approach here but you could make get() and set() methods hookable by wrapping them in ___get() and ___set() methods respectively (prefixed with tripple underscore). It will cause problems when you upgrade PW though. You'd better wait for an answer from more seasoned developer out there ;)

Cheers.

Link to comment
Share on other sites

Raoul, I don't think you can easily change the storage mechanism for sessions at this time. However, you'll be glad to know that the option of database session storage is a priority for the next version and the code is already underway here. Until that time, I'm not sure how you could run ProcessWire admin. But are you certain the server doesn't allow file-based sessions? PHP uses files for sessions natively, and by default, so it would be unusual in any hosting environment for that not to be an option. If you want to tell me more about the hosting environment, perhaps we can find a way around whatever limitation is in place there.

Link to comment
Share on other sites

Hi Ryan,

yes the environnement is a bit unusual due to scalabilty priorities:

The architecture consist of a loadbalanced set of x slaves servers and one master (load balancer/ mysql director), each time you request the website you never know which slave server is handling the response,

mysql handle that fine: one master which read/write and replicate on mysql slaves, so if you want to write and read right after, you better rw on the master due to replication delays.

this mechanism is not existing for the filesystem, don't know if it's possible/usable in session usage.

many thanks for your inputs, I think that I will do with my customs libraries afterall,

and get back on processwire for the next project! because pw looks very promising :)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...