Jump to content

Large array as session variable?


PaulR

Recommended Posts

I'm reading a text file of around 3MB (about 150K lines of text) into an array in index.php and need to access it in subsequent pages that aren't included in index.php ie so I can't use a global variable.

 

Will saving the array to session in index.php for later manipulation be any different to re-reading the file myself performance wise?

 

Cheers

 

Paul

Link to comment
Share on other sites

Sounds like a really bad design decision to me. What exactly is in this file? Does it vary in some way by user?

 

The idea is for users to 'drop-in' a text file and have it analysed by the program. The file could be 20K or it could be 3MB in size and needs to remain in it's native format rather than being imported into a database.

 

So far I've found performance to be reasonable when just re-reading the file but ideally I'd like to get it into memory to speed up access...the analysis program is pretty straightforward, so maybe I can stuff all the code into one file and have done with it!

 

Paul

Link to comment
Share on other sites

A server with sufficient memory will do a really good job of caching the file system data. Typically a linux server will use memory that is not otherwise allocated as file system buffer memory, so this may explain why you are seeing good performance. With that said, if you really want to ensure that you are getting memory speed caching, I would suggest you look at using APC, Memcache or Redis, and explicitly put in caching calls for this data. Since you should have an opcode cache installed anyways, I'd start with APC, assuming you are in a single server setup.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.