user972946
user972946

Reputation:

Is there an application scope variable feature in PHP?

I wish to store a variable to be accessible by all sessions, similar to the idea of "application object" in ASP. Is this feature supported by PHP?

Upvotes: 2

Views: 312

Answers (2)

Colselaw
Colselaw

Reputation: 1079

Because the original architecture of PHP is based on CGI, inherently, no. There might be something in container-based PHP's, but I don't believe there's anything in the API.

That being said, there's support for global caches, which run in a process outside of PHP.

What are you trying to accomplish? Generally, trying to do a straight translation of ASP code to PHP won't get you far - same for changing from any one language/platform to another - you have to free your mind and learn to think the way of the platform you're learning.

Upvotes: 1

Tom van der Woerdt
Tom van der Woerdt

Reputation: 29985

Sounds like you want to store a variable between page requests, but not grouped by session but global across all users?

Why not just write it to a file?

// Read
$variable = unserialize(file_get_contents('/path/to/applicationVariable.txt'));

// Write
file_put_contents('/path/to/applicationVariable.txt', serialize($variable));

(Note: of course, the filesystem isn't the best place for these. A database or cache server might be better suited, depending on what it's for.)

Upvotes: 0

Related Questions