ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
nusoap_wsdlcache Class Reference

caches instances of the wsdl class More...

+ Inheritance diagram for nusoap_wsdlcache:
+ Collaboration diagram for nusoap_wsdlcache:

Public Member Functions

 nusoap_wsdlcache ($cache_dir='.', $cache_lifetime=0)
 constructor
 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)
 adds a wsdl instance to the cache
 releaseMutex ($filename)
 releases the local mutex
 remove ($wsdl)
 removes a wsdl instance from the cache

Data Fields

 $fplock
 $cache_lifetime
 $cache_dir
 $debug_str = ''

Detailed Description

caches instances of the wsdl class

Author
Scott Nichol snich.nosp@m.ol@u.nosp@m.sers..nosp@m.sour.nosp@m.cefor.nosp@m.ge.n.nosp@m.et
Ingo Fischer ingo@.nosp@m.apol.nosp@m.lon.d.nosp@m.e
Version
Id:
class.wsdlcache.php,v 1.7 2007/04/17 16:34:03 snichol Exp

public

Definition at line 18 of file class.wsdlcache.php.

Member Function Documentation

nusoap_wsdlcache::createFilename (   $wsdl)

creates the filename used to cache a wsdl instance

Parameters
string$wsdlThe URL of the wsdl instance
Returns
string The filename used to cache the instance private

Reimplemented in wsdlcache.

Definition at line 60 of file class.wsdlcache.php.

References $wsdl.

Referenced by get(), put(), and remove().

{
return $this->cache_dir.'/wsdlcache-' . md5($wsdl);
}

+ Here is the caller graph for this function:

nusoap_wsdlcache::debug (   $string)

adds debug data to the class level debug string

Parameters
string$stringdebug data private

Reimplemented in wsdlcache.

Definition at line 70 of file class.wsdlcache.php.

Referenced by get(), obtainMutex(), put(), releaseMutex(), and remove().

{
$this->debug_str .= get_class($this).": $string\n";
}

+ Here is the caller graph for this function:

nusoap_wsdlcache::get (   $wsdl)

gets a wsdl instance from the cache

Parameters
string$wsdlThe URL of the wsdl instance
Returns
object wsdl The cached wsdl instance, null if the instance is not in the cache public

Reimplemented in wsdlcache.

Definition at line 81 of file class.wsdlcache.php.

References $filename, $wsdl, createFilename(), debug(), obtainMutex(), and releaseMutex().

{
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");
return null;
}
}
// see what there is to return
if (!file_exists($filename)) {
$this->debug("$wsdl ($filename) not in cache (1)");
return null;
}
$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 (2)");
}
return (!is_null($s)) ? unserialize($s) : null;
} else {
$this->debug("Unable to obtain mutex for $filename in get");
}
return null;
}

+ Here is the call graph for this function:

nusoap_wsdlcache::nusoap_wsdlcache (   $cache_dir = '.',
  $cache_lifetime = 0 
)

constructor

Parameters
string$cache_dirdirectory for cache-files
integer$cache_lifetimelifetime for caching-files in seconds or 0 for unlimited public

Definition at line 47 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;
}
nusoap_wsdlcache::obtainMutex (   $filename,
  $mode 
)

obtains the local mutex

Parameters
string$filenameThe Filename of the Cache to lock
string$modeThe open-mode ("r" or "w") or the file - affects lock-mode
Returns
boolean Lock successfully obtained ?! private

Reimplemented in wsdlcache.

Definition at line 124 of file class.wsdlcache.php.

References $filename, and 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);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

nusoap_wsdlcache::put (   $wsdl_instance)

adds a wsdl instance to the cache

Parameters
objectwsdl $wsdl_instance The wsdl instance to add
Returns
boolean WSDL successfully cached public

Reimplemented in wsdlcache.

Definition at line 144 of file class.wsdlcache.php.

References $filename, createFilename(), debug(), obtainMutex(), and releaseMutex().

{
$filename = $this->createFilename($wsdl_instance->wsdl);
$s = serialize($wsdl_instance);
if ($this->obtainMutex($filename, "w")) {
$fp = fopen($filename, "w");
if (! $fp) {
$this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache");
return false;
}
fputs($fp, $s);
fclose($fp);
$this->debug("Put $wsdl_instance->wsdl ($filename) in cache");
return true;
} else {
$this->debug("Unable to obtain mutex for $filename in put");
}
return false;
}

+ Here is the call graph for this function:

nusoap_wsdlcache::releaseMutex (   $filename)

releases the local mutex

Parameters
string$filenameThe Filename of the Cache to lock
Returns
boolean Lock successfully released private

Reimplemented in wsdlcache.

Definition at line 172 of file class.wsdlcache.php.

References $filename, $ret, and debug().

Referenced by get(), put(), and remove().

{
$ret = flock($this->fplock[md5($filename)], LOCK_UN);
fclose($this->fplock[md5($filename)]);
unset($this->fplock[md5($filename)]);
if (! $ret) {
$this->debug("Not able to release lock for $filename");
}
return $ret;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

nusoap_wsdlcache::remove (   $wsdl)

removes a wsdl instance from the cache

Parameters
string$wsdlThe URL of the wsdl instance
Returns
boolean Whether there was an instance to remove public

Reimplemented in wsdlcache.

Definition at line 189 of file class.wsdlcache.php.

References $filename, $ret, $wsdl, createFilename(), debug(), obtainMutex(), and releaseMutex().

{
if (!file_exists($filename)) {
$this->debug("$wsdl ($filename) not in cache to be removed");
return false;
}
// ignore errors obtaining mutex
$this->obtainMutex($filename, "w");
$ret = unlink($filename);
$this->debug("Removed ($ret) $wsdl ($filename) from cache");
return $ret;
}

+ Here is the call graph for this function:

Field Documentation

nusoap_wsdlcache::$cache_dir

Definition at line 33 of file class.wsdlcache.php.

Referenced by nusoap_wsdlcache().

nusoap_wsdlcache::$cache_lifetime

Definition at line 28 of file class.wsdlcache.php.

Referenced by nusoap_wsdlcache().

nusoap_wsdlcache::$debug_str = ''

Definition at line 38 of file class.wsdlcache.php.

nusoap_wsdlcache::$fplock

Definition at line 23 of file class.wsdlcache.php.


The documentation for this class was generated from the following file: