Re: Any alternative to Enviroment Variables?

From: Date: Sat, 06 Jan 2001 04:11:21 +0000
Subject: Re: Any alternative to Enviroment Variables?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33012@lists.php.net to get a copy of this message
> Hi! I was wondering if there is a way to declare a variable (maybe in the > php.ini) that can be referenced as global, similar to eviroment variables. > The thing is i don´t want to initialize it in every script. Depending on why you want to do this, there's several options: 1. If you just don't want the hassle of typing the same code every time, look at the auto_prepend stuff in php.ini 1a. You may want to look into making it a CONSTANT using http://php.net/define 2. If you are trying to store a large amount of data or complex calculation result in one shared memory space to save on initialization time, and if you have access to the user PHP runs as, usually "nobody" or "www" or something similar, as defined in httpd.conf in Apache, you could set an environment variable in their shell environment, I think. In a PHP Module, that *might* be evaluated only once when httpd starts up. Then a GetEnv in each script (or in 1 above) might be an easy read-only shared value... [Disclaimer: I just made this up -- I dunno if it works or if anybody ever tried it.] 3. Another possibiity is that you need a single variable shared across multiple instances of PHP. If so, look into the "Sys V" "shared memory" compilation switches and documentation http://php.net/manual/ref.sem.php Not for the faint of heart, but definitely the right solution to inter-process communication where opening a database is "too slow". 4. Finally, if the goal is to share data for a variable between processes, keep in mind that if you are already opening and using a database connection, executing another query or two is pretty darn cheap. So if (3) leaves your mind reeling, try just using your existing database knowledge.

« previous php.general (#33012) next »