Re: Re: Statics and PHP5
| From: | Adam Bregenzer | Date: | Tue, 17 Feb 2004 15:47:16 +0000 |
| Subject: | Re: Re: Statics and PHP5 | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7927@lists.php.net to get a copy of this message | ||
On Tue, 2004-02-17 at 06:07, Derick Rethans wrote:
> I don't want to plug anything, but have a look at www.vl-srm.net; it
> tries to achive this (note: site is a bit outdated).
You don't have to plugin anything, you can do it in PHP and the data
storage method of your choice. Keep in mind that srm is a PHP extension
and therefore less portable than just using PHP code. Srm's design is
certainly much more robust than what I have below, but here's a basic
pseudo code example of global variables using shared memory and very
simple locking. You could extend this to also save and restore static
variables in objects.
function retrieveGlobalVar($var_name) {
if (shmGetVal($var_name . '-lock') == '0') {
// grab variable from storage
$val = unserialize(shmGetVal($var_name));
// Lock variable automatically
lockGlobalVar($var_name);
// return variable
return $val;
} else {
// Locked
return null;
}
}
function saveAndReleaseGlobalVar($var_name, $var) {
// save variable
shmSetVal($var_name, serialize($var));
// Unlock variable automatically
unlockGlobalVar($var_name);
}
function deleteGlobalVar($var_name) {
// Delete variable
shmDeleteVal($var_name);
// Delete variable's locking value
shmDeleteVal($var_name . '-lock');
}
function lockGlobalVar($var_name) {
// mark variable as locked
shmSetVal($var_name . '-lock', '1');
}
function unlockGlobalVar($var_name) {
// mark variable as unlocked
shmSetVal($var_name . '-lock', '0');
}
Regards,
Adam
--
Adam Bregenzer
adam@bregenzer.net
http://adam.bregenzer.net/