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

**URL:** <https://discourse.laminas.dev/t/looking-for-a-kind-of-persistent-globals-variable-between-2-http-queries/2722>\
**Category:** Components & MVC\
**Tags:** zend-cache\
**Created:** [January 18, 2022, 9:33am UTC](https://discourse.laminas.dev/t/looking-for-a-kind-of-persistent-globals-variable-between-2-http-queries/2722 "2022-01-18T09:33:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![devEric69](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/deveric69/32/1228_2.png) [@devEric69](https://discourse.laminas.dev/u/devEric69)\
**Post date:** [January 18, 2022, 9:33am UTC](https://discourse.laminas.dev/t/looking-for-a-kind-of-persistent-globals-variable-between-2-http-queries/2722/1 "2022-01-18T09:33:09Z")

</div>

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 🫤 . 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?

---

<div class="post-metadata">

**Author:** ![ocramius](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ocramius/32/23_2.png) [@ocramius](https://discourse.laminas.dev/u/ocramius)\
**Post date:** [January 18, 2022, 12:56pm UTC](https://discourse.laminas.dev/t/looking-for-a-kind-of-persistent-globals-variable-between-2-http-queries/2722/2 "2022-01-18T12:56:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![devEric69](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/deveric69/32/1228_2.png) [@devEric69](https://discourse.laminas.dev/u/devEric69)\
**Post date:** [January 20, 2022, 5:23pm UTC](https://discourse.laminas.dev/t/looking-for-a-kind-of-persistent-globals-variable-between-2-http-queries/2722/3 "2022-01-20T17:23:29Z")

</div>

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).
