Reading and writing global variables across scripts in PHP

Robin Rodricks picture Robin Rodricks · Sep 17, 2009 · Viewed 11.5k times · Source

Does PHP have global variables that can be modified by one running script and read by another?

Answer

Brenton Alker picture Brenton Alker · Sep 17, 2009

No, by design PHP is a "share nothing" architecture, which means nothing is shared between processes running at the same time or between requests running one after another. There are ways to share data, but you have to do it explicitly.

If you just want to share between 2 requests from the same user, sessions or cookies might be the way to go.

If you want to share between multiple users, you probably want some sort of shared persistence, either short term in a cache (eg. memcached) or more robust like a database.

Either way, the data is actually being retrieved and reconstructed on each request. It's just handled automatically for you in the case of sessions.