[newbie][php] global array
Dear all,
I have a general question regarding php. Suppose that I want to have an array that stores connection-specific data, that can be anything IP address or something similar. However, whenever I use global or server variables (i.e. GLOBALS or _SERVER) the array created in this way is kind of connection-oriented, so that for each connection there is a seperate instance of this array. Maybe it has something to do with the MPM of Apache, but I am not sure. Is it possible to implement an array that stores information about all connections that are at a system? In this way, each connection can chip in and upload it with data? Also, I would rather not use cookie's.. Thank you for all your suggestions, Cheers! |
You should look at session variables:
http://www.php.net/manual/en/book.session.php It normally uses a cookie to separate the sessions. But you can override it: http://www.php.net/manual/en/session.idpassing.php Edit: If you want the data to be truly global (shared between all), you can store it a file or a database. |
Quote:
|
So it doesn't need to be persistent? I think you need to elaborate more on what you need. If you think files are slow, what about the PHP file itself? And fast connections are usually not the problem with the database. Slow connections are worse because they keep the connection open, and the database will get problems if there are too many open at once.
Anyway, if you don't use a database, you will need to think of locking and multiple updates happening at the same time. You could use semaphores or shared memory, but to me it smells like premature optimization. http://www.php.net/manual/en/book.sem.php http://www.php.net/manual/en/book.shmop.php |
All times are GMT -5. The time now is 10:14 PM. |