pantheon-systems / wp-native-php-sessions

Implement native PHP sessions stored in the database for WordPress.
https://wordpress.org/plugins/wp-native-php-sessions/
GNU General Public License v2.0
138 stars 43 forks source link

I'm not sure what I have to do to get the plugin working #248

Open maxacarvalho opened 1 year ago

maxacarvalho commented 1 year ago

Hi,

I installed the plugin on a fresh (latest) WordPress installation. I can see that the table wp_pantheon_sessions was created successfully. But no entries are being added to that table. I don't see anything listed under the Tools > Sessions area.

As I mentioned, this is a fresh WordPress installation.
The only other plugin that I added so far is the Send E-mails with Mandrill, one which is only a way to send emails using Mandrill by MailChimp.

I wonder if there's any extra step that I have to take, perhaps some PHP configuration that's necessary?

I'm using:

Thank you.

jazzsequence commented 1 year ago

@maxacarvalho I guess I would ask how you are using sessions in your codebase? As noted in the plugin's description, the intent is to allow native handling of PHP's $_SESSION global which is otherwise unavailable in WordPress. If you aren't using $_SESSION then it's not going to look like it's doing anything.

maxacarvalho commented 1 year ago

Hi @jazzsequence Thanks for your reply. To be honest, I don't know how to make that happen using WordPress. I'm 100% comfortable with PHP. I have been using it for more than ten years. But when it comes to WordPress, I'm useless. This is a project that I put together for a client that needs WordPress.
Since our setup uses Kubernetes, it's possible that each deployment drops all user sessions since WordPress (weirdly enough) offers only file-based sessions natively. For that reason, I'm trying to move those sessions to long-living storage.

I chose the database since the website doesn't have heavy traffic; otherwise, I'd go for something faster like Redis.
Your plugin is the only option that I could find for WordPress DB sessions, another fact that I find very odd since that's a very common approach.

I'm sorry to give you such a long response, but I just wanted to give you a full context instead of just saying, "I don't know how to get the $_SESSION to be global when it comes to WordPress".

jazzsequence commented 1 year ago

WordPress is indeed weird when it comes to session handling which is why this plugin exists. The configuration and usage is described in the readme -- after installing and activating the plugin, native PHP sessions should Just Work™️. If you're seeing errors or evidence that sessions aren't being stored and recovered properly, then that would be something for us to dig into. After activating this plugin (or loading it as an mu-plugin) all your previous PHP experience in session handling should all be applicable and it should behave the way you expect.

I apologize if I'm stating the obvious but without any specific errors or reproducible steps it's difficult to say what you're doing "wrong". I will say that I would not be surprised by sessions clearing after a deployment, but I do think that that would be a case that would be handled by the plugin (since the sessions are stored in the database).