Re: [PHP-CVS] cvs: php4 /pear/Cache Container.php Output.php/pear/Cache/Container db.php file.php phplib.php
>> Modified files: >> /php4/pear/CacheContainer.php Output.php >> /php4/pear/Cache/Container db.php file.php phplib.php >> Log: >> Introduced getExpiresAbsolute($expire) function, which translates >> relative/human readable/unixtime expire-times in unixtime-format. > > > Could some kind soul have a look at the cvs commit mail script and let it > send commit mails regarding PEAR/ to the new pear-cvs mailing list? NONONO! pear-cvs@ will be the list for commits for the PEAR not the PHP repository, no change is needed here... andré -- · André Langhorstt: +49 331 5811560 · · [EMAIL PROTECTED] m: +49 173 9558736 · * PHP Quality Assurance http://qa.php.net * -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-CVS] cvs: php4 /pear/Cache Container.php Output.php/pear/Cache/Container db.php file.php phplib.php
Christian Stocker wrote: > chregu Thu Mar 8 03:57:16 2001 EDT > > Modified files: > /php4/pear/CacheContainer.php Output.php > /php4/pear/Cache/Container db.php file.php phplib.php > Log: > Introduced getExpiresAbsolute($expire) function, which translates > relative/human readable/unixtime expire-times in unixtime-format. Could some kind soul have a look at the cvs commit mail script and let it send commit mails regarding PEAR/ to the new pear-cvs mailing list? Thanks, Sebastian -- sebastian bergmann e-mail : [EMAIL PROTECTED] homepage : http://www.sebastian-bergmann.de make a gift : http://wishlist.sebastian-bergmann.de measure the usability of your web application -> http://phpOpenTracker.de -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear/Cache Container.php Output.php /pear/Cache/Container db.php file.php phplib.php
chregu Thu Mar 8 03:57:16 2001 EDT Modified files: /php4/pear/CacheContainer.php Output.php /php4/pear/Cache/Container db.php file.php phplib.php Log: Introduced getExpiresAbsolute($expire) function, which translates relative/human readable/unixtime expire-times in unixtime-format. Index: php4/pear/Cache/Container.php diff -u php4/pear/Cache/Container.php:1.6 php4/pear/Cache/Container.php:1.7 --- php4/pear/Cache/Container.php:1.6 Tue Mar 6 07:27:30 2001 +++ php4/pear/Cache/Container.php Thu Mar 8 03:57:15 2001 @@ -14,9 +14,10 @@ // +--+ // | Authors: Ulf Wendel <[EMAIL PROTECTED]> | // | Sebastian Bergmann <[EMAIL PROTECTED]> | +// | Christian Stocker <[EMAIL PROTECTED]> | // +--+ // -// $Id: Container.php,v 1.6 2001/03/06 15:27:30 sbergmann Exp $ +// $Id: Container.php,v 1.7 2001/03/08 11:57:15 chregu Exp $ /** * Common base class of all cache storage container. @@ -36,7 +37,7 @@ * not recommended! * * @author Ulf Wendel <[EMAIL PROTECTED]> -* @version $Id: Container.php,v 1.6 2001/03/06 15:27:30 sbergmann Exp $ +* @version $Id: Container.php,v 1.7 2001/03/08 11:57:15 chregu Exp $ * @package Cache * @access public * @abstract @@ -372,5 +373,47 @@ else return unserialize($data); } // end func decode + +/** +* Translates human readable/relative times in unixtime +* +* @var mixed can be in the following formats: +* human readable : mmddhhmm[ss]] eg: 20010308095100 +* relative in seconds (1) : +xx eg: +10 +* relative in seconds (2) : x < 946681200 eg: 10 +* absolute unixtime : x < 2147483648 eg: 2147483648 +* see comments in code for details +*/ + +function getExpiresAbsolute($expires) + +{ +if (!$expires) +return 0; +//for api-compatibility, one has not to provide a "+", +// if integer is < 946681200 (= Jan 01 2000 00:00:00) +if ('+' == $expires[0] || $expires < 946681200) +{ +return(time() + $expires); +} +//if integer is < 1000 (= in 3140 years), +// it must be an absolut unixtime +// (since the "human readable" definition asks for a higher number) +elseif ($expires < 1000) +{ +return $expires; +} +// else it's "human readable"; +else +{ +$year = substr($expires, 0, 4); +$month = substr($expires, 4, 2); +$day = substr($expires, 6, 2); +$hour = substr($expires, 8, 2); +$minute = substr($expires, 10, 2); +$second = substr($expires, 12, 2); +return mktime($hour, $minute, $second, $month, $day, $year); +} +} } ?> Index: php4/pear/Cache/Output.php diff -u php4/pear/Cache/Output.php:1.9 php4/pear/Cache/Output.php:1.10 --- php4/pear/Cache/Output.php:1.9 Tue Mar 6 07:27:30 2001 +++ php4/pear/Cache/Output.php Thu Mar 8 03:57:15 2001 @@ -17,7 +17,7 @@ // | Vinai Kopp <[EMAIL PROTECTED]> | // +--+ // -// $Id: Output.php,v 1.9 2001/03/06 15:27:30 sbergmann Exp $ +// $Id: Output.php,v 1.10 2001/03/08 11:57:15 chregu Exp $ require_once 'Cache.php'; @@ -129,11 +129,11 @@ /* * Stores the content of the output buffer into the cache and returns the content. * -* @paraminteger lifetime of the cached data in seconds - 0 for endless +* @parammixed lifetime of the cached data in seconds - 0 for endless. More +formats available. see Container::getExpiresAbsolute() * @paramstring additional userdefined data * @return string cached output * @access public -* @see endPrint(), endGet() +* @see endPrint(), endGet(), Container::getExpiresAbsolute() */ function end($expire = 0, $userdata = "") { $content = ob_get_contents(); Index: php4/pear/Cache/Container/db.php diff -u php4/pear/Cache/Container/db.php:1.7 php4/pear/Cache/Container/db.php:1.8 --- php4/pear/Cache/Container/db.php:1.7Tue Mar 6 07:27:30 2001 +++ php4/pear/Cache/Container/db.phpThu Mar 8 03:57:16 2001 @@ -17,7 +17,7 @@ // | Chuck Hagenbuch <[EMAIL PROTECTED]> | // +--+ // -// $Id: db.php,v 1.7 2001/03/06 15:27:30 sbergmann Exp $ +// $Id: db.php,v 1.8 2001/03/08 11:57:16 chregu Exp $ require_once 'DB.php'; require_once 'Cache/Container.php'; @@ -52,7 +52,7 @@ * ) * * @author Sebastian Be
[PHP-CVS] cvs: php4 /pear/Cache Container.php /pear/Cache/Container db.php phplib.php
chregu Tue Mar 6 03:32:10 2001 EDT Modified files: /php4/pear/CacheContainer.php /php4/pear/Cache/Container db.php phplib.php Log: replaced db->quoteString with addslashes adjusted encoding_mode = "slash" that it doesn't quote slashes, the save() function in phplib/db-container is now in charge for that. Index: php4/pear/Cache/Container.php diff -u php4/pear/Cache/Container.php:1.4 php4/pear/Cache/Container.php:1.5 --- php4/pear/Cache/Container.php:1.4 Sat Mar 3 11:14:36 2001 +++ php4/pear/Cache/Container.php Tue Mar 6 03:32:10 2001 @@ -1,4 +1,5 @@ | // +--+ // -// $Id: Container.php,v 1.4 2001/03/03 19:14:36 uw Exp $ +// $Id: Container.php,v 1.5 2001/03/06 11:32:10 chregu Exp $ /** * Common base class of all cache storage container. @@ -36,7 +37,7 @@ * not recommended! * * @author Ulf Wendel <[EMAIL PROTECTED]> -* @version $Id: Container.php,v 1.4 2001/03/03 19:14:36 uw Exp $ +* @version $Id: Container.php,v 1.5 2001/03/06 11:32:10 chregu Exp $ * @package Cache * @access public * @abstract @@ -215,7 +216,7 @@ * @return boolean */ function isCached($id, $group) { - + if ($this->preload) { if ($this->id != $id || $this->group != $group) @@ -343,7 +344,7 @@ // Uuups, unknown ID $this->flushPreload(); - + return false; } @@ -406,7 +407,7 @@ if ("base64" == $this->encoding_mode) return base64_encode(serialize($data)); else -return addslashes(serialize($data)); +return serialize($data); } // end func encode @@ -421,9 +422,9 @@ if ("base64" == $this->encoding_mode) return unserialize(base64_decode($data)); else -return unserialize(stripslashes($data)); +return unserialize($data); } // end func decode } -?> \ No newline at end of file +?> Index: php4/pear/Cache/Container/db.php diff -u php4/pear/Cache/Container/db.php:1.5 php4/pear/Cache/Container/db.php:1.6 --- php4/pear/Cache/Container/db.php:1.5Sat Mar 3 11:01:03 2001 +++ php4/pear/Cache/Container/db.phpTue Mar 6 03:32:10 2001 @@ -17,7 +17,7 @@ // | Chuck Hagenbuch <[EMAIL PROTECTED]> | // +--+ // -// $Id: db.php,v 1.5 2001/03/03 19:01:03 uw Exp $ +// $Id: db.php,v 1.6 2001/03/06 11:32:10 chregu Exp $ require_once 'DB.php'; require_once 'Cache/Container.php'; @@ -52,7 +52,7 @@ * ) * @author Sebastian Bergmann <[EMAIL PROTECTED]> - * @version $Id: db.php,v 1.5 2001/03/03 19:01:03 uw Exp $ + * @version $Id: db.php,v 1.6 2001/03/06 11:32:10 chregu Exp $ * @package Cache */ class Cache_Container_db extends Cache_Container { @@ -107,8 +107,8 @@ { $query = sprintf("SELECT cachedata, userdata, expires FROM %s WHERE id = '%s' AND cachegroup = '%s'", $this->cache_table, - $this->db->quoteString($id), - $this->db->quoteString($group) + addslashes($id), + addslashes($group) ); $res = $this->db->query($query); @@ -117,7 +117,7 @@ return new CacheError('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); $row = $res->fetchRow(); - + if (is_array($row)) return array($row['expires'], $this->decode($row['cachedata']), $row['userdata']); } @@ -136,17 +136,17 @@ $query = sprintf("REPLACE INTO %s (userdata, cachedata, expires, id, cachegroup) VALUES ('%s', '%s', %d, '%s', '%s')", $this->cache_table, - $this->db->quoteString($userdata), - $this->db->quoteString($this->encode(($data))), + addslashes($userdata), + addslashes($this->encode($data)), ($expires) ? $expires + time() : 0, - $this->db->quoteString($id), - $this->db->quoteString($group) + addslashes($id), + addslashes($group) ); - + $res = $this->db->query($query); if (DB::isError($res)) { -return new CacheError('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); +return new CacheError('DB::query failed: ' . DB::errorMessage($res) , +__FILE__, __LINE__); } } @@ -157,8 +157,8 @@ $query = sprintf("DELETE FROM %s WHERE id = '%s' and cachegroup = '%s'",
Re: [PHP-CVS] cvs: php4 /pear/Cache Container.php
On Sat, Mar 03, 2001 at 07:14:36PM -, Ulf Wendel wrote: > PR: > What does PR mean - Public Relations? In this context, it means "Problem Report". It should probably be renamed "Bug:" and filled in with the bug ID when the commit closes an open bug in the PHP bug tracker. -- Jon Parise ([EMAIL PROTECTED]) . Rochester Inst. of Technology http://www.csh.rit.edu/~jon/ : Computer Science House Member -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear/Cache Container.php
uw Sat Mar 3 11:14:36 2001 EDT Modified files: /php4/pear/CacheContainer.php Log: PR: What does PR mean - Public Relations? Anyway: new cache structure/features - allowed to group cache datasets in a group - allowed to add userdata [CHAR(255)] to a dataset in the cache More explanations will follow on the PEAR list. Submitted by: Ulf Wendel <[EMAIL PROTECTED]> Reviewed by: myself ;-) works on my development system and my homepage Index: php4/pear/Cache/Container.php diff -u php4/pear/Cache/Container.php:1.3 php4/pear/Cache/Container.php:1.4 --- php4/pear/Cache/Container.php:1.3 Fri Mar 2 06:30:03 2001 +++ php4/pear/Cache/Container.php Sat Mar 3 11:14:36 2001 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <[EMAIL PROTECTED]> | // +--+ // -// $Id: Container.php,v 1.3 2001/03/02 14:30:03 uw Exp $ +// $Id: Container.php,v 1.4 2001/03/03 19:14:36 uw Exp $ /** * Common base class of all cache storage container. @@ -36,7 +36,7 @@ * not recommended! * * @author Ulf Wendel <[EMAIL PROTECTED]> -* @version $Id: Container.php,v 1.3 2001/03/02 14:30:03 uw Exp $ +* @version $Id: Container.php,v 1.4 2001/03/03 19:14:36 uw Exp $ * @package Cache * @access public * @abstract @@ -59,6 +59,15 @@ */ var $id = ""; + +/** +* Cache group of a preloaded dataset +* +* @var string +*/ +var $group = ""; + + /** * Expiration timestamp of a preloaded dataset. * @@ -66,66 +75,108 @@ */ var $expires = 0; + /** * Value of a preloaded dataset. * * @var string */ -var $data = ""; +var $cachedata = ""; + /** +* Preloaded userdata field. +* +* @var string +*/ +var $userdata = ""; + + +/** * Flag indicating that the dataset requested for preloading is unknown. * * @var boolean */ var $unknown = true; + /** * Encoding mode for cache data: base64 or addslashes() (slash). * * @var string base64 or slash */ var $encoding_mode = "base64"; + /** * Loads a dataset from the cache. * * @paramstring dataset ID +* @paramstring cache group * @return mixed dataset value or NULL on failure * @access public */ -function load($id) { +function load($id, $group) { if ($this->preload) { -if ($this->id != $id) -$this->preload($id); +if ($this->id != $id || $this->group != $group) +$this->preload($id, $group); -return $this->data; +return $this->cachedata; } else { -list( , $data) = $this->fetch($id); +list( , $data, ) = $this->fetch($id, $group); return $data; } } // end func load + +/** +* Returns the userdata field of a cached data set. +* +* @paramstring dataset ID +* @paramstring cache group +* @return string userdata +* @access public +*/ +function getUserdata($id, $group) { + +if ($this->preload) { + +if ($this->id != $id || $this->group != $group) +$this->preload($id, $group); + +return $this->userdata; + +} else { + +list( , , $userdata) = $this->fetch($id, $group); +return $userdata; + +} + +} // end func getUserdata + + /** * Checks if a dataset is expired. * * @paramstring dataset ID +* @paramstring cache group * @paraminteger maximum age timestamp * @return boolean * @access public */ -function isExpired($id, $max_age = 0) { +function isExpired($id, $group, $max_age) { if ($this->preload) { - if ($this->id != $id) -$this->preload($id); + if ($this->id != $id || $this->group != $group) +$this->preload($id, $group); if ($this->unknown) return false; @@ -133,11 +184,11 @@ } else { // check if at all it is cached -if (!$this->isCached($id)) +if (!$this->isCached($id, $group)) return false; // I'm lazy... -list($this->expires, ) = $this->fetch($id); +list($this->expires, , ) = $this->fetch($id, $group); } // endless @@ -147,7 +198,7 @@ // you feel fine, Ulf? if ($expired = ($this->expires <= time() || ($max_age
[PHP-CVS] cvs: php4 /pear/Cache Container.php
uw Fri Mar 2 06:30:04 2001 EDT Modified files: /php4/pear/CacheContainer.php Log: - changed $max_age to an absolute timestamp value Index: php4/pear/Cache/Container.php diff -u php4/pear/Cache/Container.php:1.2 php4/pear/Cache/Container.php:1.3 --- php4/pear/Cache/Container.php:1.2 Thu Mar 1 09:18:22 2001 +++ php4/pear/Cache/Container.php Fri Mar 2 06:30:03 2001 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <[EMAIL PROTECTED]> | // +--+ // -// $Id: Container.php,v 1.2 2001/03/01 17:18:22 sbergmann Exp $ +// $Id: Container.php,v 1.3 2001/03/02 14:30:03 uw Exp $ /** * Common base class of all cache storage container. @@ -36,7 +36,7 @@ * not recommended! * * @author Ulf Wendel <[EMAIL PROTECTED]> -* @version $Id: Container.php,v 1.2 2001/03/01 17:18:22 sbergmann Exp $ +* @version $Id: Container.php,v 1.3 2001/03/02 14:30:03 uw Exp $ * @package Cache * @access public * @abstract @@ -100,6 +100,7 @@ if ($this->id != $id) $this->preload($id); + return $this->data; } else { @@ -115,7 +116,7 @@ * Checks if a dataset is expired. * * @paramstring dataset ID -* @paraminteger maximum age in seconds of the data set +* @paraminteger maximum age timestamp * @return boolean * @access public */ @@ -144,7 +145,7 @@ return false; // you feel fine, Ulf? -if ($expired = ($this->expires <= time() || ($max_age && $this->expires <= time() + $max_age)) ) { +if ($expired = ($this->expires <= time() || ($max_age && ($this->expires <= +$max_age))) ) { $this->delete($id); $this->flushPreload(); @@ -167,7 +168,7 @@ if ($this->id != $id) $this->preload($id); -return !($this->unknown); +return !($this->unknown); } else { @@ -270,6 +271,7 @@ $this->id = $id; list($this->expires, $this->data) = $this->fetch($id); + if (NULL === $this->data) { // Uuups, unknown ID -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear/Cache Container.php /pear/Cache/Container file.php phplib.php shm.php
sbergmann Thu Mar 1 09:18:23 2001 EDT Modified files: /php4/pear/CacheContainer.php /php4/pear/Cache/Container file.php phplib.php shm.php Log: Added flushPreload() method. Index: php4/pear/Cache/Container.php diff -u php4/pear/Cache/Container.php:1.1 php4/pear/Cache/Container.php:1.2 --- php4/pear/Cache/Container.php:1.1 Thu Mar 1 08:32:29 2001 +++ php4/pear/Cache/Container.php Thu Mar 1 09:18:22 2001 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <[EMAIL PROTECTED]> | // +--+ // -// $Id: Container.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $ +// $Id: Container.php,v 1.2 2001/03/01 17:18:22 sbergmann Exp $ /** * Common base class of all cache storage container. @@ -36,7 +36,7 @@ * not recommended! * * @author Ulf Wendel <[EMAIL PROTECTED]> -* @version $Id: Container.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $ +* @version $Id: Container.php,v 1.2 2001/03/01 17:18:22 sbergmann Exp $ * @package Cache * @access public * @abstract @@ -147,13 +147,8 @@ if ($expired = ($this->expires <= time() || ($max_age && $this->expires <= time() + $max_age)) ) { $this->delete($id); + $this->flushPreload(); - // remove preloaded values - $this->id = ""; - $this->data = ""; - $this->expires = 0; - $this->unknown = true; - } return $expired; @@ -210,6 +205,7 @@ * @abstract */ function save($id, $data, $expire = 0) { +$this->flushPreload($id); return NULL; } // end func save @@ -223,6 +219,7 @@ * @abstract */ function delete($id) { +$this->flushPreload($id); return NULL; } // end func delete @@ -235,6 +232,7 @@ * @abstract */ function flush() { +$this->flushPreload(); return NULL; } // end func flush @@ -257,6 +255,7 @@ * @abstract */ function garbageCollection() { +$this->flushPreload(); } // end func garbageCollection /** @@ -288,6 +287,27 @@ return true; } // end func preload +/** +* Flushes the internal preload buffer. +* +* save(), delete() and flush() must call this method +* to preevent differences between the preloaded values and +* the real cache contents. +* +* @see preload() +*/ +function flushPreload($id = "") { + +if (!$id || $this->id == $id) { +// clear the internal preload values +$this->id = ""; +$this->data = ""; +$this->expires = -1; +$this->unknown = true; +} + +} // end func flushPreload + /** * Imports the requested datafields as object variables if allowed * Index: php4/pear/Cache/Container/file.php diff -u php4/pear/Cache/Container/file.php:1.1 php4/pear/Cache/Container/file.php:1.2 --- php4/pear/Cache/Container/file.php:1.1 Thu Mar 1 08:32:29 2001 +++ php4/pear/Cache/Container/file.php Thu Mar 1 09:18:23 2001 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <[EMAIL PROTECTED]> | // +--+ // -// $Id: file.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $ +// $Id: file.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $ require_once 'Cache/Container.php'; @@ -24,7 +24,7 @@ * Stores cache contents in a file. * * @author Ulf Wendel <[EMAIL PROTECTED]> -* @version $Id: file.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $ +* @version $Id: file.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $ */ class Cache_Container_file extends Cache_Container { @@ -94,6 +94,8 @@ function save($id, $data, $expire = 0) { +$this->flushPreload($id); + $file = $this->getFilename($id); if (!($fh = @fopen($file, "wb"))) return new CacheError("Can't access '$file' to store cache data. Check access rights and path.", __FILE__, __LINE__); @@ -115,6 +117,8 @@ function delete($id) { +$this->flushPreload($id); + $file = $this->getFilename($id); if (file_exists($file)) { @@ -130,6 +134,8 @@ function flush() { +$this->flushPreload(); + if (!($dh = opendir($this->cache_dir))) return new CacheError("Can't access the cache directory '$this->cache_dir'. Check access rights and path", __FILE__, __LINE__); @@ -167,6 +173,8 @@ */ function garbageCollection() { +$this->flushPreload(); + if (!($dh = opendir($this->cache_dir))) return new CacheError("Can't access cache directory.", __FILE__, __LINE__); Index: php4/pear/Cache/Container/phplib.php diff -u php4/pear/Cache/Conta