Welcome Guest, Not a member yet? Register   Sign In
Global Array at Application level

Hello Everyone
I want to make global array at application level without using session. Once the application execution begins first time data comes from database and stored in array then next everytime data should be loaded from array instead of database.

Thanks in advance

Hastimal Shah

Due to the stateless nature of the web, I believe you would have to do this with sessions or cookies. You could store the serialized info in a cookie, and read that on each page, however you will run into storage issues as cookies are small. Easiest way I can see would be a session. Any reason you don't want to use sessions? Seems like this is kind of what they are designed for.


A website doesn't have a single entry point like desktop applications, it has as many as there are pages. So to make sure the data is called you need to execute it with every request. You could build in a check to see if there are modifications or not, or you could generate the static file with the array as soon as the modifications are made.

[eluser]Phil Sturgeon[/eluser]
Store it in a cache file (serialize() array in a .cache file) and just wipe those files every time the data is changed. If it is data thats subject to frequent change then obviously you wont be able to cache it.

MP_Cache is one library that can do this, but it is rather buggy.

You should then be able to access any of this data via $this->mp_cache->get(), or "extend Controller class" to get it from the text file once and keep it in a $this->data array. Let me know if you need more information

Theme © iAndrew 2016 - Forum software by © MyBB