Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading and writing global variables across scripts in PHP

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

like image 518
Robin Rodricks Avatar asked Nov 30 '22 06:11

Robin Rodricks


1 Answers

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.

like image 138
Brenton Alker Avatar answered Dec 04 '22 05:12

Brenton Alker