Public Member Functions | Data Fields

wsdlcache Class Reference

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 = ''

Detailed Description

caches instances of the wsdl class

Author:
Scott Nichol <snichol@computer.org>
Ingo Fischer <ingo@apollon.de>
Version:
Id:
class.wsdlcache.php 9095 2005-11-08 13:17:14Z smeyer

public

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


Member Function Documentation

wsdlcache::createFilename ( wsdl  ) 

creates the filename used to cache a wsdl instance

Parameters:
string $wsdl The URL of the wsdl instance
Returns:
string The filename used to cache the instance protected

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

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

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

Here is the caller graph for this function:

wsdlcache::debug ( string  ) 

adds debug data to the class level debug string

Parameters:
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";
        }

Here is the caller graph for this function:

wsdlcache::get ( wsdl  ) 

gets a wsdl instance from the cache

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

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;
        }

Here is the call graph for this function:

wsdlcache::obtainMutex ( filename,
mode 
)

obtains the local mutex

Parameters:
string $filename The Filename of the Cache to lock
string $mode The open-mode ("r" or "w") or the file - affects lock-mode
Returns:
boolean Lock successfully obtained ?! protected

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);
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

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;
        }

Here is the call graph for this function:

wsdlcache::releaseMutex ( filename  ) 

releases the local mutex

Parameters:
string $filename The Filename of the Cache to lock
Returns:
boolean Lock successfully released protected

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;
        }

Here is the caller graph for this function:

wsdlcache::remove ( wsdl  ) 

removes a wsdl instance from the cache

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

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;
        }

Here is the call graph for this function:

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;
        }


Field Documentation

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.


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