caches instances of the wsdl class More...
Public Member Functions | |
wsdlcache ($cache_dir='.', $cache_lifetime=0) | |
createFilename ($wsdl) | |
creates the filename used to cache a wsdl instance | |
debug ($string) | |
adds debug data to the class level debug string | |
get ($wsdl) | |
gets a wsdl instance from the cache | |
obtainMutex ($filename, $mode) | |
obtains the local mutex | |
put ($wsdl_instance) | |
releaseMutex ($filename) | |
releases the local mutex | |
remove ($wsdl) | |
removes a wsdl instance from the cache | |
Data Fields | |
$fplock | |
$cache_lifetime | |
$cache_dir | |
$debug_str = '' |
caches instances of the wsdl class
public
Definition at line 13 of file class.wsdlcache.php.
wsdlcache::createFilename | ( | $ | wsdl | ) |
creates the filename used to cache a wsdl instance
string | $wsdl The URL of the wsdl instance |
Definition at line 39 of file class.wsdlcache.php.
Referenced by get(), put(), and remove().
{ return $this->cache_dir.'/wsdlcache-' . md5($wsdl); }
wsdlcache::debug | ( | $ | string | ) |
adds debug data to the class level debug string
string | $string debug data private |
Definition at line 49 of file class.wsdlcache.php.
Referenced by get(), obtainMutex(), put(), and remove().
{
$this->debug_str .= get_class($this).": $string\n";
}
wsdlcache::get | ( | $ | wsdl | ) |
gets a wsdl instance from the cache
string | $wsdl The URL of the wsdl instance |
Definition at line 60 of file class.wsdlcache.php.
References createFilename(), debug(), obtainMutex(), and releaseMutex().
{ $filename = $this->createFilename($wsdl); if ($this->obtainMutex($filename, "r")) { // check for expired WSDL that must be removed from the cache if ($this->cache_lifetime > 0) { if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) { unlink($filename); $this->debug("Expired $wsdl ($filename) from cache"); $this->releaseMutex($filename); return null; } } // see what there is to return $fp = @fopen($filename, "r"); if ($fp) { $s = implode("", @file($filename)); fclose($fp); $this->debug("Got $wsdl ($filename) from cache"); } else { $s = null; $this->debug("$wsdl ($filename) not in cache"); } $this->releaseMutex($filename); return (!is_null($s)) ? unserialize($s) : null; } return null; }
wsdlcache::obtainMutex | ( | $ | filename, | |
$ | mode | |||
) |
obtains the local mutex
string | $filename The Filename of the Cache to lock | |
string | $mode The open-mode ("r" or "w") or the file - affects lock-mode |
Definition at line 96 of file class.wsdlcache.php.
References debug().
Referenced by get(), put(), and remove().
{ if (isset($this->fplock[md5($filename)])) { $this->debug("Lock for $filename already exists"); return false; } $this->fplock[md5($filename)] = fopen($filename.".lock", "w"); if ($mode == "r") { return flock($this->fplock[md5($filename)], LOCK_SH); } else { return flock($this->fplock[md5($filename)], LOCK_EX); } }
wsdlcache::put | ( | $ | wsdl_instance | ) |
Definition at line 116 of file class.wsdlcache.php.
References createFilename(), debug(), obtainMutex(), and releaseMutex().
{ $filename = $this->createFilename($wsdl_instance->wsdl); $s = serialize($wsdl_instance); if ($this->obtainMutex($filename, "w")) { $fp = fopen($filename, "w"); fputs($fp, $s); fclose($fp); $this->debug("Put $wsdl_instance->wsdl ($filename) in cache"); $this->releaseMutex($filename); return true; } return false; }
wsdlcache::releaseMutex | ( | $ | filename | ) |
releases the local mutex
string | $filename The Filename of the Cache to lock |
Definition at line 137 of file class.wsdlcache.php.
Referenced by get(), put(), and remove().
{
$ret = flock($this->fplock[md5($filename)], LOCK_UN);
fclose($this->fplock[md5($filename)]);
unset($this->fplock[md5($filename)]);
return $ret;
}
wsdlcache::remove | ( | $ | wsdl | ) |
removes a wsdl instance from the cache
string | $wsdl The URL of the wsdl instance |
Definition at line 151 of file class.wsdlcache.php.
References createFilename(), debug(), obtainMutex(), and releaseMutex().
{ $filename = $this->createFilename($wsdl); $this->obtainMutex($filename, "w"); $ret = unlink($filename); $this->debug("Removed $wsdl ($filename) from cache"); $this->releaseMutex($filename); return $ret; }
wsdlcache::wsdlcache | ( | $ | cache_dir = '.' , |
|
$ | cache_lifetime = 0 | |||
) |
Definition at line 26 of file class.wsdlcache.php.
References $cache_dir, and $cache_lifetime.
{ $this->fplock = array(); $this->cache_dir = $cache_dir != '' ? $cache_dir : '.'; $this->cache_lifetime = $cache_lifetime; }
wsdlcache::$cache_dir |
Definition at line 16 of file class.wsdlcache.php.
Referenced by wsdlcache().
wsdlcache::$cache_lifetime |
Definition at line 15 of file class.wsdlcache.php.
Referenced by wsdlcache().
wsdlcache::$debug_str = '' |
Definition at line 17 of file class.wsdlcache.php.
wsdlcache::$fplock |
Definition at line 14 of file class.wsdlcache.php.