Looking for a kind of *persistent* $GLOBALS variable between 2 HTTP queries

Hello,

I know that the HTTP protocol is stateless between 2 HTTP queries. Nevertheless, I’m trying to find out if there are ways to leave persistent global variables in the HTTP server’s RAM between two users requests: I’m thinking in particular of a big routes table array.

Concerning my research on the internet, I saw that Php 8.1 adds a new API: apc_store. For the moment, I am in Php 7.2 :face_with_diagonal_mouth: . I know solutions like “redis” too.

But I’m looking if something simpler exists like a kind of super $GLOBALS always in HTTP server’s RAM from HTTP query call to another HTTP query call. Do you know, do you recommend a particular Php library easy to use? I’ve seen that there’s a ZF3 component called zend-cache: can it be used to do what I am looking for?

Hey Eric,

PHP’s default model (when using PHP-FPM or mod_php) is to not share any state between requests: all state needs to be stored/loaded between different requests (except for extremely exotic setups, that I do not endorse to anyone new to this).

If the state is well-formed in shape and behavior, then I suggest using a DB construct (table or similar), not a cache.

Caches are designed to persist some state that you can afford to lose and share between multiple clients, mostly for performance reasons.

If your state is well defined, give it a name, a good table definition, and save it properly.

Okay. Also, I’ve just checked: being on a mutualized \ shared server, APC (a kind of equivalent to a shareable file mapped in RAM between several processes i.e. between several subsequent \ parallel requests, whether those requests are issued from the same web-client or from different web-clients) isn’t available.

Thanks for confirming what I thought (I’m technically forced to use, at best, a global SQL table. But it’s already a good thing).