Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discourage the use of PHP Sessions #2475

Open
1 task
apermo opened this issue Aug 18, 2024 · 0 comments
Open
1 task

Discourage the use of PHP Sessions #2475

apermo opened this issue Aug 18, 2024 · 0 comments

Comments

@apermo
Copy link

apermo commented Aug 18, 2024

Is your feature request related to a problem?

PHP Sessions are not used within WordPress core, and a few years back, I've talked with @2ndkauboy about wether to use them in a plugin or not. He advised against it, but did not really know why you should avoid using it.

In a recent project I found an objective reason why.

On the site I'm working on, which is quite big, I had to optimize long delays within the backend. In the end there were two major issues that I fixed, that improved the backend performance. Number one, was related to the vast amount of attachments. Number two was about session_start().

In my case Ninja Firewall is using php session, this becomes a problem as soon as multiple requests are fired in short succession, and when one request lasts a little longer.

And when opening the block editor it is absolutely normal that 5-15 requests are fired in the instance that you open the editor.

After profiling with xhprof I saw the following results (simplified)

Request 1: 9s due to a bunch of curl requests.
Request 2: 9.3s, 9s of it just waiting for session_start() and 0.3s for the actual execution
Request 3: 9.6s, 9.3s waiting for session_start()
Similar picture for the next requests.

I could bypass this issue, by adding a redis server to our project structure, but this will not be a solution for everyone.

Describe the solution you'd like

Similar to a warning when using some ini_set() that have WordPress functions for it, or when using a meta_query I would like to see a notice, that using session_start() or accessing $_SESSION is discouraged and considered a bad practice within WordPress.

I second what Juliette wrote in the below referenced issue, that WordPress Extra would be the right place for this.

Additional context (optional)

Back in 2013 this was already discussed but only added to WordPress VIP
In 2022 this was again discussed within the yoastcs project. where @jrfnl already suggested to create a ticket upstream (which is done hereby)

For completeness the Links that Juliette gathered:

  • I intend to create a pull request to implement this feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants