|
Posted by Al on 02/01/06 19:30
Jim Carlock wrote:
> <xclarky@gmail.com> posted:
> > Have you considered using sessions? You could use them to create
> > a temporary cache of the array quite easily.
>
> <?php
> session_start();
> if (!isset($_SESSION['array_cache'])) {
> $array = array('value', 'value');
> $_SESSION['array_cache'] = $array;
> } else {
> $array = $_SESSION['array_cache'];
> }
> ?>
>
> Thanks, Clark(?). I'll give that a go.
>
> Jim Carlock
> Post replies to the newsgroup.
I admit I don't know the internal workings of PHP too well, but I'm
really not sure storing the array as a session variable will actually
help anything.
As far as I can tell session variables are just little text files
stored server-side per connection. As such there are two points:
1) you're just loading the array from a text file, so it makes no
difference whether you're loading it from the text file or creating it
in the script
2) it may actually be serialised to be put in said text file, and as
such you're actually incurring extra time serialising and unserialising
it every page refresh.
Plus even if this way does manage to save some server processing (in a
way I can't see) then it'll only work on subsequent page loads of each
session. As such the array still has to be created once per
user/session of the web site. If the array isn't going to change it
might be best to create the array and serialise it to a text file
that's open for everyone. That way the script can just load it from
there even for the first load per session. And if it only changes every
now and again (i.e. with an update from you rather than in the script
over a session) then you can make a separate script that will load it
in, make the changes, and then save it again.
But I could be way off with the way sessions work.
[Back to original message]
|