View Feed
group-icon
PHP Programmers
Community for PHP Programmers : Ask questions, doubts and help each other get better at PHP
299 Members
Join this group to post and comment.
Kaustubh Katdare
Kaustubh Katdare • Sep 8, 2017

Are PHP sessions reliable?

I'm wondering if PHP sessions are reliable; especially when there are 200-300 simultaneous users writing to it. This question is in context of the Quizzr App on CrazyEngineers IO that makes use of PHP Sessions to store some temporary data. We've noticed that when there are large number of simultaneous users, there 'might' be a case that the sessions tend to lose some of its data. This 'might' result into weird behaviour of the app for some of the quiz-takers. I'm saying 'might' because we haven't been able to pin-point the issue so far. It certainly NEVER occurs in our testing environment when there are 20-30 simultaneous users.

The server runs on HHVM and makes use of the SSD; so session R/W should not be an issue. I am unsure whether HHVM actually does in-memory caching of the sessions data to speed up the things and the last I checked, memcached doesn't play nice with HHVM. That said, I've also noticed app performance issue when running PHP 7.1.

Does anyone among us have thoughts or opinions about using php sessions? Would love to hear from you.

Tagging @Prasad Ajinkya and @simplycoder and @Manish Goyal to kick-start this discussion.
simplycoder
simplycoder • Sep 20, 2017
Generally speaking sessions on web servers are not something I prefer if any other option is available.

One of reason is it decreases the scalability of application.
Also you have mentioned temporary data, it is also important how much is that data in terms of size.
Generally 1-2KB data is acceptable (This needs to be measured though).

Its tough to answer this question unless we know for what purpose session is used (Like keeping user profile info or quiz-ids etc).
Kaustubh Katdare
Kaustubh Katdare • Sep 20, 2017
Thanks, @simplycoder . This discussion is in reference to the Quizzr App; where we keep lot of our data in the sessions when the user is playing the quiz. Once the quiz is over, we write the data to the database.

At the time of designing the system, I thought I'd be able to cache the data using memcached and thus avoid accessing the disk while the quiz is in progress. However, we've now been using HHVM and it does not support memcached. I'm now stuck with writing sessions data to files on the disk.

The system still works because we have SSDs and haven't faced any issues. I'm now thinking of replacing sessions with Redis so that we can do a better job of maintaining the data in memory and make it available faster for all the results calculation.

The only issue I've faced so far is that sometimes, some of the members lose access to the sessiosn data; but I've not been able to confirm this with 100% confdence. I'm not sure if it's the sessions or something else; because the issue appears only when we've 500-800 people playing the quiz at the same time, each writing to sessions.
kunaljd
kunaljd • Sep 20, 2017
Using redis will be a good idea. i would recommend to use mongodb, as it is very very fast and you can store the data of every transaction quickly.
All depends on the HHVM,as it may or may not support MongoDB.
Kaustubh Katdare
Kaustubh Katdare • Sep 20, 2017
kunaljd
i would recommend to use mongodb, as it is very very fast and you can store the data of every transaction quickly.
Thanks. MongoDB ain't the ideal solution for the job. We'll need to have an in-memory cache and Redis seems to be the ideal candidate.
kunaljd
kunaljd • Sep 20, 2017
Yes, for in-memory cache, redis will be best option possible. mongo db is disk based db,but it can also handle big volume of data.I assumed that Mango Db is fast but what i have read about redis, its lighting fast.

Supporting Docs:
https://www.quora.com/How-does-a-se...fferent-users-in-large-numbers-simultaneously

Please check this video:


So as per the this video, using redis as a buffer before Mongo DB . this is one option can be used for large chunk of data. May be this can handle 15k quizzer users per quiz.😁

Thanks

Share this content on your social channels -