diff options
| author | Ludovic Arnaud <ludovic_arnaud@users.sourceforge.net> | 2003-01-31 01:43:09 +0000 |
|---|---|---|
| committer | Ludovic Arnaud <ludovic_arnaud@users.sourceforge.net> | 2003-01-31 01:43:09 +0000 |
| commit | 5b0315305fc5e50338ca61b6b8671c45f39bf724 (patch) | |
| tree | b3bfdee6fc9b772fa8a8549597b7972ca8d10518 /phpBB/includes/acm | |
| parent | 1c391dc290d25d181fd265f02221a9ffd2fca2fc (diff) | |
| download | forums-5b0315305fc5e50338ca61b6b8671c45f39bf724.tar forums-5b0315305fc5e50338ca61b6b8671c45f39bf724.tar.gz forums-5b0315305fc5e50338ca61b6b8671c45f39bf724.tar.bz2 forums-5b0315305fc5e50338ca61b6b8671c45f39bf724.tar.xz forums-5b0315305fc5e50338ca61b6b8671c45f39bf724.zip | |
I thought I had committed this already :-/
(fixed slashing of data, added file locking)
git-svn-id: file:///svn/phpbb/trunk@3436 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/acm')
| -rw-r--r-- | phpBB/includes/acm/cache_file.php | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/phpBB/includes/acm/cache_file.php b/phpBB/includes/acm/cache_file.php index 5bd9c452f4..c9b4008a50 100644 --- a/phpBB/includes/acm/cache_file.php +++ b/phpBB/includes/acm/cache_file.php @@ -99,10 +99,6 @@ class acm if ($expire_time > 0) { - if (!isset($this->vars[$varname])) - { - return FALSE; - } if ($this->vars_ts[$varname] <= time() - $expire_time) { $this->destroy($varname); @@ -131,9 +127,13 @@ class acm global $phpEx; $file = '<?php $this->vars=' . $this->format_array($this->vars) . ";\n\$this->vars_ts=" . $this->format_array($this->vars_ts) . ' ?>'; - $fp = fopen($this->cache_dir . 'global.' . $phpEx, 'wb'); - fwrite($fp, $file); - fclose($fp); + if ($fp = @fopen($this->cache_dir . 'global.' . $phpEx, 'wb')) + { + @flock($fp, LOCK_EX); + fwrite($fp, $file); + @flock($fp, LOCK_UN); + fclose($fp); + } } function format_array($array) @@ -155,7 +155,7 @@ class acm } else { - $lines[] = "'$k'=>'" . str_replace('\\\\', '\\\\\\\\', str_replace("'", "\'", $v)) . "'"; + $lines[] = "'$k'=>'" . str_replace("'", "\'", str_replace('\\', '\\\\', $v)) . "'"; } } return 'array(' . implode(',', $lines) . ')'; @@ -182,28 +182,32 @@ class acm function sql_save($query, $result) { global $db, $phpEx; - $fp = fopen($this->cache_dir . md5($query) . '.' . $phpEx, 'wb'); - - $lines = array(); - $query_id = 'Cache id #' . count($this->sql_rowset); - $this->sql_rowset[$query_id] = array(); - $this->sql_rowset_index[$query_id] = 0; - $db->query_result = $query_id; - - while ($row = $db->sql_fetchrow($result)) + if (@$fp = fopen($this->cache_dir . md5($query) . '.' . $phpEx, 'wb')) { - $this->sql_rowset[$query_id][] = $row; + @flock($fp, LOCK_EX); + + $lines = array(); + $query_id = 'Cache id #' . count($this->sql_rowset); + $this->sql_rowset[$query_id] = array(); + $this->sql_rowset_index[$query_id] = 0; + $db->query_result = $query_id; - $line = 'array('; - foreach ($row as $key => $val) + while ($row = $db->sql_fetchrow($result)) { - $line .= "'$key'=>'" . str_replace('\\\\', '\\\\\\\\', str_replace("'", "\'", $val)) . "',"; + $this->sql_rowset[$query_id][] = $row; + + $line = 'array('; + foreach ($row as $key => $val) + { + $line .= "'$key'=>'" . str_replace("'", "\'", str_replace('\\', '\\\\', $val)) . "',"; + } + $lines[] = substr($line, 0, -1) . ')'; } - $lines[] = substr($line, 0, -1) . ')'; - } - fwrite($fp, "<?php\n\n/*\n$query\n*/\n\n\$rowset = array(" . implode(',', $lines) . ') ?>'); - fclose($fp); + fwrite($fp, "<?php\n\n/*\n$query\n*/\n\n\$rowset = array(" . implode(',', $lines) . ') ?>'); + @flock($fp, LOCK_UN); + fclose($fp); + } } function sql_exists($query_id) @@ -213,6 +217,8 @@ class acm function sql_fetchrow($query_id) { + //return array_shift($this->sql_rowset[$query_id]); + if (!isset($this->sql_rowset[$query_id][$this->sql_rowset_index[$query_id]])) { return false; |
