Is it good practice to try to save a “generic” array in the $_SESSION array for the purpose of applyng e.g PHP sorting functions instead of calling a new result set from the server? Seems abit overkill to e.g call a new result set if I want to sort comments based on likes instead of timestamp. Maybe there is another best practice for this “problem”? How much efficiency is there to be gained working like this? Is it very much?
Share
That may be a very good option, or a disastrous one.
You have the advantages clear, or it seems that way, but the drawbacks are immense depending on the number of users, the frequency of changes of those results, the size of the array etc.
If you plan on keeping it as a global variable during the life of the script, it’s not bad.
If you have very few users, then it may be ok, but consider the size.
If the results are going to change often, then you have double work since you have to keep checking that the values in the session are still fresh and right to use.
With out the complete set of data about users, frequency of use, etc, I’ll say that you should not use that option.