Thread: [Phpfreechat-svn] SF.net SVN: phpfreechat: [478] trunk/src/containers/file.class.php
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-04-27 10:09:56
|
Revision: 478 Author: kerphi Date: 2006-04-27 03:09:45 -0700 (Thu, 27 Apr 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=478&view=rev Log Message: ----------- code cleaning : remove unused code Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-04-26 17:49:18 UTC (rev 477) +++ trunk/src/containers/file.class.php 2006-04-27 10:09:45 UTC (rev 478) @@ -118,23 +118,7 @@ flock ($fp, LOCK_UN); // unlock fclose($fp); - - /** - * @todo: this is not the container' job to keep synchronized the user' metadatas ! - */ - - // update the user's metadata (channels) - if ($chan != NULL) - { - $userchan = $this->getMeta("channels", "nickname", $nick); - $userchan = $userchan != NULL ? unserialize($userchan) : array(); - if (!in_array($chan, $userchan)) - { - $userchan[] = $chan; - $this->setMeta(serialize($userchan), "channels", "nickname", $nick); - } - } - + // if (!in_array($nickname, $this->_users)) // $this->_users[] = $nickname; // _users will be used by getOnlineUserList @@ -166,31 +150,6 @@ @unlink($nick_filename); - - - /** - * @todo: this is not the container' job to keep synchronized the user' metadatas ! - */ - - // update the user's metadata (channels) - if ($chan != NULL) - { - // the user just disconnect from a channel - $userchan = $this->getMeta("channels", "nickname", $nick); - $userchan = $userchan != NULL ? unserialize($userchan) : array(); - if (in_array($chan, $userchan)) - { - $key = array_search($chan, $userchan); - unset($userchan[$key]); - $this->setMeta(serialize($userchan), "channels", "nickname", $nick); - } - } - else - { - // the user disconnect from the whole server - $this->rmMeta("channels", "nickname", $nick); - } - /* // remove the nickname from the cache list if (in_array($nick, $this->_users)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-05-27 10:29:34
|
Revision: 510 Author: kerphi Date: 2006-05-27 03:29:24 -0700 (Sat, 27 May 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=510&view=rev Log Message: ----------- fix some php warnings when directories doesn't exists Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-05-26 20:56:29 UTC (rev 509) +++ trunk/src/containers/file.class.php 2006-05-27 10:29:24 UTC (rev 510) @@ -185,6 +185,7 @@ $nick_dir = ($chan != NULL) ? $c->container_cfg_channel_dir."/".$this->_encode($chan)."/nicknames" : $c->container_cfg_server_dir."/nicknames"; + if (!is_dir($nick_dir)) mkdir_r($nick_dir); // update my online status file $nick_filename = $nick_dir."/".$this->_encode($nick); @@ -338,7 +339,8 @@ $nick_dir = ($chan != NULL) ? $c->container_cfg_channel_dir."/".$this->_encode($chan)."/nicknames" : $c->container_cfg_server_dir."/nicknames"; - + if (!is_dir($nick_dir)) mkdir_r($nick_dir); + $users = array(); $dir_handle = opendir($nick_dir); while (false !== ($file = readdir($dir_handle))) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-06 23:58:21
|
Revision: 1093 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1093&view=rev Author: gpinzone Date: 2007-08-06 16:58:20 -0700 (Mon, 06 Aug 2007) Log Message: ----------- Changed popMeta to act more like a traditional pop command than a drop in replacement for existing algorithm. Cleaned up setMeta. Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-08-06 19:59:53 UTC (rev 1092) +++ trunk/src/containers/file.class.php 2007-08-06 23:58:20 UTC (rev 1093) @@ -248,35 +248,33 @@ { $ret["value"][] = chop(fread($fh, filesize($leaffilename))); $ret["timestamp"][] = filemtime($leaffilename); - $leafvalue = $ret; - array_pop($leafvalue); + $leafvalue = array_pop($ret); // check if array is now empty - if (count($leafvalue) == 0) + if (count($ret) == 0) { + fclose($fh); unlink($leaffilename); break; } rewind($fh); - fwrite($fh, $leafvalue); + fwrite($fh, $ret); fflush($fh); ftruncate($fh, ftell($fh)); flock($fh, LOCK_UN); + fclose($fh); break; } // If flock is working properly, this will never be reached $delay = rand(0, pow(2, ($i+1)) - 1) * 5000; // Exponential backoff usleep($delay); } - fclose($fh); + $ret = $leafvalue; } else { + // return empty array return $ret; } - - $ret["value"][] = $leafvalue; - $ret["timestamp"][] = filemtime($leaffilename); - return $ret; } @@ -295,11 +293,6 @@ // create or replace metadata file $leaffilename = $dir."/".$leaf; - // create return array - $ret = array(); - $ret["timestamp"] = array(); - $ret["value"] = array(); - // read and increment data from metadata file clearstatcache(); if ( $leafexists = file_exists($leaffilename) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2008-05-16 07:20:20
|
Revision: 1240 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1240&view=rev Author: kerphi Date: 2008-05-16 00:20:26 -0700 (Fri, 16 May 2008) Log Message: ----------- Fixes the timeout problem for special servers which do not update the file timestamp when the content doesn't change Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2008-05-04 06:47:21 UTC (rev 1239) +++ trunk/src/containers/file.class.php 2008-05-16 07:20:26 UTC (rev 1240) @@ -99,7 +99,7 @@ $leafexists = file_exists($leaffilename); if ($leafvalue == NULL) { - file_put_contents($leaffilename, '', LOCK_EX); + touch($leaffilename); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2008-05-23 20:54:44
|
Revision: 1241 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1241&view=rev Author: kerphi Date: 2008-05-23 13:54:51 -0700 (Fri, 23 May 2008) Log Message: ----------- Add a test on the LOCK_EX feature in the initialisation process. This feature doesn't work on filesystems like NFS. Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2008-05-16 07:20:26 UTC (rev 1240) +++ trunk/src/containers/file.class.php 2008-05-23 20:54:51 UTC (rev 1241) @@ -70,18 +70,29 @@ $timetowait = 2; if (is_writable(dirname($filename))) { - file_put_contents($filename,'some-data1-'.time(), LOCK_EX); + file_put_contents($filename,'some-data1-'.time()); clearstatcache(); $time1 = filemtime($filename); sleep($timetowait); - file_put_contents($filename,'some-data2-'.time(), LOCK_EX); + file_put_contents($filename,'some-data2-'.time()); clearstatcache(); $time2 = filemtime($filename); unlink($filename); if ($time2-$time1 != $timetowait) - $errors[] = "filemtime php fuction is not usable on your filesystem. Please do not use the 'file' container (try the 'mysql' container) or swith to another filesystem."; + $errors[] = "filemtime php fuction is not usable on your filesystem. Please do not use the 'file' container (try the 'mysql' container) or swith to another filesystem type."; } + // test the LOCK_EX feature because it doesn't work on special filsystem like NFS + $filename = $c->data_private_path.'/filemtime.test'; + if (is_writable(dirname($filename))) + { + $data1 = time(); + file_put_contents($filename, $data1, LOCK_EX); + $data2 = file_get_contents($filename); + if ($data1 != $data2) + $errors[] = "LOCK_EX feature is not usable on your filesystem. Please do not use the 'file' container (try the 'mysql' container) or swith to another filesystem type."; + } + return $errors; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-05-28 11:50:45
|
Revision: 514 Author: kerphi Date: 2006-05-28 04:50:35 -0700 (Sun, 28 May 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=514&view=rev Log Message: ----------- add few comments Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-05-27 19:11:04 UTC (rev 513) +++ trunk/src/containers/file.class.php 2006-05-28 11:50:35 UTC (rev 514) @@ -509,7 +509,7 @@ * @param $key is the index which identify a metadata * @param $type is used to "group" some metadata * @param $subtype is used to "group" precisely some metadata, use NULL to ignore it - * @return mixed the value assigned to the key + * @return mixed the value assigned to the key, NULL if not found */ function getMeta($key, $type, $subtype = NULL) { @@ -538,6 +538,7 @@ * @param $value is the value associated to the key * @param $type is used to "group" some metadata * @param $subtype is used to "group" precisely some metadata, use NULL to ignore it + * @return true on success, false on error */ function setMeta($value, $key, $type, $subtype = NULL) { @@ -568,6 +569,7 @@ * @param $key is the key to delete, use NULL to delete all the metadata * @param $type is used to "group" some metadata * @param $subtype is used to "group" precisely some metadata, use NULL to ignore it + * @return true on success, false on error */ function rmMeta($key, $type, $subtype = NULL) { @@ -612,6 +614,7 @@ /** * Return a unique id. Each time this function is called, the last id is incremented. * used internaly + * @private */ function _requestMsgId($chan) { @@ -647,12 +650,20 @@ return $msg_id; } - + + /** + * Used to encode UTF8 strings to ASCII filenames + * @private + */ function _encode($str) { return base64_encode(urlencode($str)); } + /** + * Used to decode ASCII filenames to UTF8 strings + * @private + */ function _decode($str) { return urldecode(base64_decode($str)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-06-15 20:55:27
|
Revision: 594 Author: kerphi Date: 2006-06-15 13:51:12 -0700 (Thu, 15 Jun 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=594&view=rev Log Message: ----------- Optimize the default file container metadata access: add a cache Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-06-15 20:31:43 UTC (rev 593) +++ trunk/src/containers/file.class.php 2006-06-15 20:51:12 UTC (rev 594) @@ -31,7 +31,8 @@ { var $_users = array("nickid" => array(), "timestamp" => array()); - + var $_meta = array(); + function pfcContainer_File(&$config) { pfcContainer::pfcContainer(&$config); @@ -571,22 +572,25 @@ */ function getMeta($key, $type, $subtype = NULL) { - $c =& $this->c; - // encode parameters $enc_key = $this->_encode($key); $enc_type = $this->_encode($type); - $enc_subtype = ($subtype == NULL) ? "" : $this->_encode($subtype); - + $enc_subtype = ($subtype == NULL) ? "NULL" : $this->_encode($subtype); + if (isset($this->_meta[$enc_type][$enc_subtype][$enc_key])) + return $this->_meta[$enc_type][$enc_subtype][$enc_key]; + // read data from metadata file + $c =& $this->c; $dir_base = $c->container_cfg_meta_dir; - $dir = $dir_base."/".$enc_type.($enc_subtype == "" ? "" : "/".$enc_subtype); + $dir = $dir_base."/".$enc_type.($enc_subtype == "NULL" ? "" : "/".$enc_subtype); $filename = $dir."/".$enc_key; $ret = @file_get_contents($filename); - if ($ret == false) - return NULL; - else - return $ret; + if ($ret == false) $ret = NULL; + + // store the result in the cache + $this->_meta[$enc_type][$enc_subtype][$enc_key] = $ret; + + return $ret; } /** @@ -600,21 +604,24 @@ */ function setMeta($value, $key, $type, $subtype = NULL) { - $c =& $this->c; - // encode parameters $enc_key = $this->_encode($key); $enc_type = $this->_encode($type); - $enc_subtype = ($subtype == NULL) ? "" : $this->_encode($subtype); - + $enc_subtype = ($subtype == NULL) ? "NULL" : $this->_encode($subtype); + // create directories + $c =& $this->c; $dir_base = $c->container_cfg_meta_dir; - $dir = $dir_base."/".$enc_type.($enc_subtype == "" ? "" : "/".$enc_subtype); + $dir = $dir_base."/".$enc_type.($enc_subtype == "NULL" ? "" : "/".$enc_subtype); if (!is_dir($dir)) mkdir_r($dir); // create or replace metadata file $filename = $dir."/".$enc_key; $ret = @file_put_contents($filename, $value); + + // store the value in the cache + if ($ret) $this->_meta[$enc_type][$enc_subtype][$enc_key] = $value; + if ($ret == false) return false; else @@ -634,24 +641,30 @@ $c =& $this->c; // encode parameters - $enc_key = ($key == NULL) ? "" : $this->_encode($key); + $enc_key = ($key == NULL) ? "NULL" : $this->_encode($key); $enc_type = $this->_encode($type); - $enc_subtype = ($subtype == NULL) ? "" : $this->_encode($subtype); + $enc_subtype = ($subtype == NULL) ? "NULL" : $this->_encode($subtype); // rm data from metadata file $dir_base = $c->container_cfg_meta_dir; - $dir = $dir_base."/".$enc_type.($enc_subtype == "" ? "" : "/".$enc_subtype); + $dir = $dir_base."/".$enc_type.($enc_subtype == "NULL" ? "" : "/".$enc_subtype); $ret = true; - if ($enc_key == "") + if ($enc_key == "NULL") { // remove all keys (the complete directory) @rm_r($dir); + + // remove the cached data + unset($this->_meta[$enc_type][$enc_subtype]); } else { // just remove one key $filename = $dir."/".$enc_key; $ret = @unlink($filename); + + // remove the cached data + unset($this->_meta[$enc_type][$enc_subtype][$enc_key]); } return $ret; @@ -666,7 +679,11 @@ $c =& $this->c; // remove the created files and directories $dir = $c->container_cfg_server_dir; - rm_r($dir); + @rm_r($dir); + // empty the cache + $this->_meta = array(); + $this->_users = array("nickid" => array(), + "timestamp" => array()); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-06-16 12:13:22
|
Revision: 595 Author: kerphi Date: 2006-06-16 05:13:17 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=595&view=rev Log Message: ----------- Warning fix: "Call-time pass-by-reference has been deprecated" Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-06-15 20:51:12 UTC (rev 594) +++ trunk/src/containers/file.class.php 2006-06-16 12:13:17 UTC (rev 595) @@ -35,7 +35,7 @@ function pfcContainer_File(&$config) { - pfcContainer::pfcContainer(&$config); + pfcContainer::pfcContainer($config); // $this->loadPaths(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-08-26 09:31:21
|
Revision: 705 Author: kerphi Date: 2006-08-26 02:31:12 -0700 (Sat, 26 Aug 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=705&view=rev Log Message: ----------- [en] Bug fix: in the default file container, the old messages were never deleted. (thanks to dan_m2k, thehermit and AkS for the bug report) [fr] Bug fix?\194?\160: dans le conteneur par d?\195?\169faut (file), les vieux messages n'?\195?\169taient jamais d?\195?\169truits. (merci ?\195?\160 dan_m2k, thehermit et AkS pour le rapport de bug) Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-08-25 19:55:44 UTC (rev 704) +++ trunk/src/containers/file.class.php 2006-08-26 09:31:12 UTC (rev 705) @@ -475,6 +475,11 @@ // write message file_put_contents($msg_filename, $data); + + // delete the obsolete message + $old_msg_id = $msg_id - $c->max_msg - 20; + if ($old_msg_id > 0 && file_exists($msg_dir."/".$old_msg_id)) + @unlink($msg_dir."/".$old_msg_id); return $msg_id; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-09-08 20:53:37
|
Revision: 737 http://svn.sourceforge.net/phpfreechat/?rev=737&view=rev Author: kerphi Date: 2006-09-08 13:53:29 -0700 (Fri, 08 Sep 2006) Log Message: ----------- code cleaning Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-09-06 06:53:04 UTC (rev 736) +++ trunk/src/containers/file.class.php 2006-09-08 20:53:29 UTC (rev 737) @@ -671,7 +671,8 @@ $ret = @unlink($filename); // remove the cached data - unset($this->_meta[$enc_type][$enc_subtype][$enc_key]); + if (isset($this->_meta[$enc_type][$enc_subtype][$enc_key])) + unset($this->_meta[$enc_type][$enc_subtype][$enc_key]); } return $ret; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-09-18 20:49:58
|
Revision: 768 http://svn.sourceforge.net/phpfreechat/?rev=768&view=rev Author: kerphi Date: 2006-09-18 13:49:50 -0700 (Mon, 18 Sep 2006) Log Message: ----------- Work in progresse : new data model (in test) Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-09-17 20:51:29 UTC (rev 767) +++ trunk/src/containers/file.class.php 2006-09-18 20:49:50 UTC (rev 768) @@ -848,6 +848,161 @@ { return urldecode(base64_decode($str)); } + + + + + + + + + + + + + + /** + * Write a meta data value identified by a group / subgroup / leaf [with a value] + * @return 1 if the leaf allready existed, 0 if the leaf has been created + */ + function setMeta2($group, $subgroup, $leaf, $leafvalue = NULL) + // value, $key, $type, $subtype = NULL) + { + // create directories + $c =& $this->c; + $dir_base = $c->container_cfg_meta_dir; + $dir = $dir_base.'/'.$group.'/'.$subgroup; + if (!is_dir($dir)) mkdir_r($dir); + + // create or replace metadata file + $leaffilename = $dir."/".$leaf; + $leafexists = file_exists($leaffilename); + if ($leafvalue == NULL) + { + @touch($leaffilename); + } + else + { + @file_put_contents($leaffilename, $leafvalue); + } + + // store the value in the memory cache + //@todo + // $this->_meta[$enc_type][$enc_subtype][$enc_key] = $value; + + if ($leafexists) + return 1; // value overwritten + else + return 0; // value created + } + + + /** + * Read meta data identified by a group [/ subgroup [/ leaf]] + * @return ... + */ + function getMeta2($group, $subgroup = null, $leaf = null, $withleafvalue = false) + //($key, $type, $subtype = NULL) + { + // @todo read the value from the memory cache + //if (isset($this->_meta[$enc_type][$enc_subtype][$enc_key])) + // return $this->_meta[$enc_type][$enc_subtype][$enc_key]; + + // read data from metadata file + $ret = array(); + $ret["timestamp"] = array(); + $ret["value"] = array(); + $c =& $this->c; + $dir_base = $c->container_cfg_meta_dir; + + $dir = $dir_base.'/'.$group; + + if ($subgroup == NULL) + { + $dh = opendir($dir); + while (false !== ($file = readdir($dh))) + { + if ($file == "." || $file == "..") continue; // skip . and .. generic files + $ret["timestamp"][] = @filemtime($dir.'/'.$file); + $ret["value"][] = $file; + } + return $ret; + } + + $dir .= '/'.$subgroup; + + if ($leaf == NULL) + { + $dh = opendir($dir); + $ret = array(); + while (false !== ($file = readdir($dh))) + { + if ($file == "." || $file == "..") continue; // skip . and .. generic files + $ret["timestamp"][] = @filemtime($dir.'/'.$file); + $ret["value"][] = $file; + } + return $ret; + } + + $leaffilename = $dir."/".$leaf; + + if (!file_exists($leaffilename)) return $ret; + if ($withleafvalue) + { + $ret["value"][] = @file_get_contents($leaffilename); + } + else + { + $ret["timestamp"][] = @filemtime($leaffilename); + } + + // @todo + // store the result in the memory cache + //$this->_meta[$enc_type][$enc_subtype][$enc_key] = $ret; + + return $ret; + } + + + /** + * Remove a meta data + * @return ... + */ + function rmMeta2($group, $subgroup = null, $leaf = null) + //($key, $type, $subtype = NULL) + { + $c =& $this->c; + + + + // read data from metadata file + $c =& $this->c; + $dir_base = $c->container_cfg_meta_dir; + + $dir = $dir_base.'/'.$group; + + if ($subgroup == NULL) + { + @rm_r($dir); + return true; + } + + $dir .= '/'.$subgroup; + + if ($leaf == NULL) + { + @rm_r($dir); + return true; + } + + $leaffilename = $dir."/".$leaf; + + if (!file_exists($leaffilename)) return false; + @unlink($leaffilename); + return true; + } + + } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-10-04 01:43:25
|
Revision: 798 http://svn.sourceforge.net/phpfreechat/?rev=798&view=rev Author: kerphi Date: 2006-09-27 09:30:22 -0700 (Wed, 27 Sep 2006) Log Message: ----------- code cleaning Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-09-26 21:02:14 UTC (rev 797) +++ trunk/src/containers/file.class.php 2006-09-27 16:30:22 UTC (rev 798) @@ -49,7 +49,7 @@ { $c =& $this->c; - $cfg = array(); + $cfg = pfcContainer::getDefaultConfig(); $cfg["chat_dir"] = ''; // will be generated from the other parameters into the init step $cfg["server_dir"] = ''; // will be generated from the other parameters into the init step return $cfg; @@ -57,7 +57,7 @@ function init() { - $errors = array(); + $errors = pfcContainer::init(); $c =& $this->c; // generate the container parameters from other config parameters This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2006-10-29 10:33:57
|
Revision: 847 http://svn.sourceforge.net/phpfreechat/?rev=847&view=rev Author: kerphi Date: 2006-10-29 02:33:50 -0800 (Sun, 29 Oct 2006) Log Message: ----------- add traces to help debugging Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-10-28 17:03:31 UTC (rev 846) +++ trunk/src/containers/file.class.php 2006-10-29 10:33:50 UTC (rev 847) @@ -74,8 +74,12 @@ function setMeta($group, $subgroup, $leaf, $leafvalue = NULL) { + $c =& $this->c; + + if ($c->debug) + file_put_contents("/tmp/debug", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND); + // create directories - $c =& $this->c; $dir_base = $c->container_cfg_server_dir; $dir = $dir_base.'/'.$group.'/'.$subgroup; if (!is_dir($dir)) mkdir_r($dir); @@ -107,11 +111,14 @@ function getMeta($group, $subgroup = null, $leaf = null, $withleafvalue = false) { + $c =& $this->c; + if ($c->debug) + file_put_contents("/tmp/debug", "\ngetMeta(".$group.",".$subgroup.",".$leaf.",".$withleafvalue.")", FILE_APPEND); + // read data from metadata file $ret = array(); $ret["timestamp"] = array(); $ret["value"] = array(); - $c =& $this->c; $dir_base = $c->container_cfg_server_dir; $dir = $dir_base.'/'.$group; @@ -163,6 +170,9 @@ function rmMeta($group, $subgroup = null, $leaf = null) { $c =& $this->c; + if ($c->debug) + file_put_contents("/tmp/debug", "\nrmMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND); + $dir = $c->container_cfg_server_dir; if ($group == NULL) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-01-12 17:22:59
|
Revision: 928 http://svn.sourceforge.net/phpfreechat/?rev=928&view=rev Author: kerphi Date: 2007-01-12 09:22:56 -0800 (Fri, 12 Jan 2007) Log Message: ----------- bug fix: it was impossible to overload the file container parameters Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-01-12 16:29:19 UTC (rev 927) +++ trunk/src/containers/file.class.php 2007-01-12 17:22:56 UTC (rev 928) @@ -36,8 +36,10 @@ function loadPaths() { $c =& $this->c; - $c->container_cfg_chat_dir = $c->data_private_path."/chat"; - $c->container_cfg_server_dir = $c->container_cfg_chat_dir."/s_".$c->serverid; + if (!isset($c->container_cfg_chat_dir)) + $c->container_cfg_chat_dir = $c->data_private_path."/chat"; + if (!isset($c->container_cfg_server_dir)) + $c->container_cfg_server_dir = $c->container_cfg_chat_dir."/s_".$c->serverid; } function getDefaultConfig() @@ -56,8 +58,6 @@ $c =& $this->c; // generate the container parameters from other config parameters - if ($c->container_cfg_chat_dir == "") - $c->container_cfg_chat_dir = $c->data_private_path."/chat"; $this->loadPaths(); $errors = array_merge($errors, @test_writable_dir($c->container_cfg_chat_dir, "container_cfg_chat_dir")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-02-20 13:47:43
|
Revision: 975 http://svn.sourceforge.net/phpfreechat/?rev=975&view=rev Author: kerphi Date: 2007-02-20 05:47:44 -0800 (Tue, 20 Feb 2007) Log Message: ----------- Bug fix : fix a "Call-time pass-by-reference has been deprecated " warning : http://www.phpfreechat.net/forum/viewtopic.php?id=1228 Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-02-20 13:43:18 UTC (rev 974) +++ trunk/src/containers/file.class.php 2007-02-20 13:47:44 UTC (rev 975) @@ -59,7 +59,7 @@ $errors = pfcContainerInterface::init($c); // generate the container parameters from other config parameters - $this->loadPaths(&$c); + $this->loadPaths($c); $errors = array_merge($errors, @test_writable_dir($c->container_cfg_chat_dir, "container_cfg_chat_dir")); $errors = array_merge($errors, @test_writable_dir($c->container_cfg_server_dir, "container_cfg_chat_dir/serverid")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-06 19:59:51
|
Revision: 1092 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1092&view=rev Author: gpinzone Date: 2007-08-06 12:59:53 -0700 (Mon, 06 Aug 2007) Log Message: ----------- Added pushMeta and popMeta for future enhancement to AppendCmdToPlay and RunPendingCmdToPlay functions. Modified Paths: -------------- trunk/src/containers/file.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-08-06 19:55:21 UTC (rev 1091) +++ trunk/src/containers/file.class.php 2007-08-06 19:59:53 UTC (rev 1092) @@ -217,6 +217,127 @@ return $ret; } + + function popMeta($group, $subgroup, $leaf) + { + $c =& pfcGlobalConfig::Instance(); + if ($c->debug) + file_put_contents("/tmp/debug", "\npopMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); + + // create directories + $dir_base = $c->container_cfg_server_dir; + $dir = $dir_base.'/'.$group.'/'.$subgroup; + if (!is_dir($dir)) mkdir_r($dir); + + // create or replace metadata file + $leaffilename = $dir."/".$leaf; + + // create return array + $ret = array(); + $ret["timestamp"] = array(); + $ret["value"] = array(); + + // read and increment data from metadata file + clearstatcache(); + if (file_exists($leaffilename)) + { + $fh = fopen($leaffilename, 'r+'); + for($i = 0; $i < 10; $i++) // Try 10 times until an exclusive lock can be obtained + { + if (flock($fh, LOCK_EX)) + { + $ret["value"][] = chop(fread($fh, filesize($leaffilename))); + $ret["timestamp"][] = filemtime($leaffilename); + $leafvalue = $ret; + array_pop($leafvalue); + // check if array is now empty + if (count($leafvalue) == 0) + { + unlink($leaffilename); + break; + } + rewind($fh); + fwrite($fh, $leafvalue); + fflush($fh); + ftruncate($fh, ftell($fh)); + flock($fh, LOCK_UN); + break; + } + // If flock is working properly, this will never be reached + $delay = rand(0, pow(2, ($i+1)) - 1) * 5000; // Exponential backoff + usleep($delay); + } + fclose($fh); + } + else + { + return $ret; + } + + $ret["value"][] = $leafvalue; + $ret["timestamp"][] = filemtime($leaffilename); + + return $ret; + } + + + function pushMeta($group, $subgroup, $leaf, $leafvalue = NULL) + { + $c =& pfcGlobalConfig::Instance(); + if ($c->debug) + file_put_contents("/tmp/debug", "\npushMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND | LOCK_EX); + + // create directories + $dir_base = $c->container_cfg_server_dir; + $dir = $dir_base.'/'.$group.'/'.$subgroup; + if (!is_dir($dir)) mkdir_r($dir); + + // create or replace metadata file + $leaffilename = $dir."/".$leaf; + + // create return array + $ret = array(); + $ret["timestamp"] = array(); + $ret["value"] = array(); + + // read and increment data from metadata file + clearstatcache(); + if ( $leafexists = file_exists($leaffilename) ) + { + $fh = fopen($leaffilename, 'r+'); + for($i = 0; $i < 10; $i++) // Try 10 times until an exclusive lock can be obtained + { + if (flock($fh, LOCK_EX)) + { + if ( $leafvalue == NULL ) $leafvalue = ''; + $leafvaltmp = chop(fread($fh, filesize($leaffilename))); + array_push($leafvaltmp, $leafvalue); + rewind($fh); + fwrite($fh, $leafvaltmp); + fflush($fh); + ftruncate($fh, ftell($fh)); + flock($fh, LOCK_UN); + break; + } + // If flock is working properly, this will never be reached + $delay = rand(0, pow(2, ($i+1)) - 1) * 5000; // Exponential backoff + usleep($delay); + } + fclose($fh); + } + else + { + file_put_contents($leaffilename, $leafvalue, LOCK_EX); + } + + if ($leafexists) + return 1; // value overwritten + else + return 0; // value created + } + + + function rmMeta($group, $subgroup = null, $leaf = null) { $c =& pfcGlobalConfig::Instance(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |