PaulR Posted February 17, 2013 Share Posted February 17, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/274587-large-array-as-session-variable/ Share on other sites More sharing options...
gizmola Posted February 17, 2013 Share Posted February 17, 2013 Sounds like a really bad design decision to me. What exactly is in this file? Does it vary in some way by user? Quote Link to comment https://forums.phpfreaks.com/topic/274587-large-array-as-session-variable/#findComment-1412898 Share on other sites More sharing options...
PaulR Posted February 17, 2013 Author Share Posted February 17, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/274587-large-array-as-session-variable/#findComment-1412903 Share on other sites More sharing options...
gizmola Posted February 17, 2013 Share Posted February 17, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274587-large-array-as-session-variable/#findComment-1412995 Share on other sites More sharing options...
PaulR Posted February 17, 2013 Author Share Posted February 17, 2013 Thank you. I'm pretty new to php and not familiar with any of those 'add-ons' but I'll certainly look into them! I've since found a few optimisations in my file reading code which will also help Paul Quote Link to comment https://forums.phpfreaks.com/topic/274587-large-array-as-session-variable/#findComment-1413010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.