diff options
Diffstat (limited to 'phpBB/phpbb/cache')
| -rw-r--r-- | phpBB/phpbb/cache/driver/apcu.php | 70 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/base.php | 16 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/dummy.php (renamed from phpBB/phpbb/cache/driver/null.php) | 8 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/eaccelerator.php | 4 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/file.php | 43 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/memcached.php | 4 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/memory.php | 16 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/driver/redis.php | 4 | ||||
| -rw-r--r-- | phpBB/phpbb/cache/service.php | 2 | 
9 files changed, 125 insertions, 42 deletions
| diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php new file mode 100644 index 0000000000..40192e4026 --- /dev/null +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -0,0 +1,70 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\cache\driver; + +/** +* ACM for APCU +*/ +class apcu extends \phpbb\cache\driver\memory +{ +	var $extension = 'apcu'; + +	/** +	* {@inheritDoc} +	*/ +	function purge() +	{ +		apcu_clear_cache(); + +		parent::purge(); +	} + +	/** +	* Fetch an item from the cache +	* +	* @access protected +	* @param string $var Cache key +	* @return mixed Cached data +	*/ +	function _read($var) +	{ +		return apcu_fetch($this->key_prefix . $var); +	} + +	/** +	* Store data in the cache +	* +	* @access protected +	* @param string $var Cache key +	* @param mixed $data Data to store +	* @param int $ttl Time-to-live of cached data +	* @return bool True if the operation succeeded +	*/ +	function _write($var, $data, $ttl = 2592000) +	{ +		return apcu_store($this->key_prefix . $var, $data, $ttl); +	} + +	/** +	* Remove an item from the cache +	* +	* @access protected +	* @param string $var Cache key +	* @return bool True if the operation succeeded +	*/ +	function _delete($var) +	{ +		return apcu_delete($this->key_prefix . $var); +	} +} diff --git a/phpBB/phpbb/cache/driver/base.php b/phpBB/phpbb/cache/driver/base.php index 53c50eeda3..f4b3dc278d 100644 --- a/phpBB/phpbb/cache/driver/base.php +++ b/phpBB/phpbb/cache/driver/base.php @@ -49,7 +49,9 @@ abstract class base implements \phpbb\cache\driver\driver_interface  				$this->remove_dir($fileInfo->getPathname());  			}  			else if (strpos($filename, 'container_') === 0 || +				strpos($filename, 'autoload_') === 0 ||  				strpos($filename, 'url_matcher') === 0 || +				strpos($filename, 'url_generator') === 0 ||  				strpos($filename, 'sql_') === 0 ||  				strpos($filename, 'data_') === 0)  			{ @@ -95,14 +97,14 @@ abstract class base implements \phpbb\cache\driver\driver_interface  	{  		// Remove extra spaces and tabs  		$query = preg_replace('/[\n\r\s\t]+/', ' ', $query); +		$query_id = md5($query); -		if (($rowset = $this->_read('sql_' . md5($query))) === false) +		if (($result = $this->_read('sql_' . $query_id)) === false)  		{  			return false;  		} -		$query_id = sizeof($this->sql_rowset); -		$this->sql_rowset[$query_id] = $rowset; +		$this->sql_rowset[$query_id] = $result;  		$this->sql_row_pointer[$query_id] = 0;  		return $query_id; @@ -181,13 +183,9 @@ abstract class base implements \phpbb\cache\driver\driver_interface  	*/  	function remove_file($filename, $check = false)  	{ -		if (!function_exists('phpbb_is_writable')) -		{ -			global $phpbb_root_path, $phpEx; -			include($phpbb_root_path . 'includes/functions.' . $phpEx); -		} +		global $phpbb_filesystem; -		if ($check && !phpbb_is_writable($this->cache_dir)) +		if ($check && !$phpbb_filesystem->is_writable($this->cache_dir))  		{  			// E_USER_ERROR - not using language entry - intended.  			trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); diff --git a/phpBB/phpbb/cache/driver/null.php b/phpBB/phpbb/cache/driver/dummy.php index a45cf97862..1f74f6dd77 100644 --- a/phpBB/phpbb/cache/driver/null.php +++ b/phpBB/phpbb/cache/driver/dummy.php @@ -14,9 +14,9 @@  namespace phpbb\cache\driver;  /** -* ACM Null Caching +* ACM dummy Caching  */ -class null extends \phpbb\cache\driver\base +class dummy extends \phpbb\cache\driver\base  {  	/**  	* Set cache path @@ -52,8 +52,10 @@ class null extends \phpbb\cache\driver\base  	*/  	function tidy()  	{ +		global $config; +  		// This cache always has a tidy room. -		set_config('cache_last_gc', time(), true); +		$config->set('cache_last_gc', time(), false);  	}  	/** diff --git a/phpBB/phpbb/cache/driver/eaccelerator.php b/phpBB/phpbb/cache/driver/eaccelerator.php index 1697758acc..740855144f 100644 --- a/phpBB/phpbb/cache/driver/eaccelerator.php +++ b/phpBB/phpbb/cache/driver/eaccelerator.php @@ -44,9 +44,11 @@ class eaccelerator extends \phpbb\cache\driver\memory  	*/  	function tidy()  	{ +		global $config; +  		eaccelerator_gc(); -		set_config('cache_last_gc', time(), true); +		$config->set('cache_last_gc', time(), false);  	}  	/** diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 1e9ee960dc..e9d2ba8e04 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -21,14 +21,26 @@ class file extends \phpbb\cache\driver\base  	var $var_expires = array();  	/** +	 * @var	\phpbb\filesystem\filesystem_interface +	 */ +	protected $filesystem; + +	/**  	* Set cache path  	*  	* @param string $cache_dir Define the path to the cache directory (default: $phpbb_root_path . 'cache/')  	*/  	function __construct($cache_dir = null)  	{ -		global $phpbb_root_path; -		$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/'; +		global $phpbb_container; + +		$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir'); +		$this->filesystem = new \phpbb\filesystem\filesystem(); + +		if (!is_dir($this->cache_dir)) +		{ +			@mkdir($this->cache_dir, 0777, true); +		}  	}  	/** @@ -63,14 +75,8 @@ class file extends \phpbb\cache\driver\base  		if (!$this->_write('data_global'))  		{ -			if (!function_exists('phpbb_is_writable')) -			{ -				global $phpbb_root_path; -				include($phpbb_root_path . 'includes/functions.' . $phpEx); -			} -  			// Now, this occurred how often? ... phew, just tell the user then... -			if (!phpbb_is_writable($this->cache_dir)) +			if (!$this->filesystem->is_writable($this->cache_dir))  			{  				// We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())  				die('Fatal: ' . $this->cache_dir . ' is NOT writable.'); @@ -89,7 +95,7 @@ class file extends \phpbb\cache\driver\base  	*/  	function tidy()  	{ -		global $phpEx; +		global $config, $phpEx;  		$dir = @opendir($this->cache_dir); @@ -143,7 +149,7 @@ class file extends \phpbb\cache\driver\base  			}  		} -		set_config('cache_last_gc', time(), true); +		$config->set('cache_last_gc', time(), false);  	}  	/** @@ -306,7 +312,7 @@ class file extends \phpbb\cache\driver\base  		// Remove extra spaces and tabs  		$query = preg_replace('/[\n\r\s\t]+/', ' ', $query); -		$query_id = sizeof($this->sql_rowset); +		$query_id = md5($query);  		$this->sql_rowset[$query_id] = array();  		$this->sql_row_pointer[$query_id] = 0; @@ -316,7 +322,7 @@ class file extends \phpbb\cache\driver\base  		}  		$db->sql_freeresult($query_result); -		if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query)) +		if ($this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl + time(), $query))  		{  			return $query_id;  		} @@ -573,13 +579,14 @@ class file extends \phpbb\cache\driver\base  				@opcache_invalidate($file);  			} -			if (!function_exists('phpbb_chmod')) +			try  			{ -				global $phpbb_root_path; -				include($phpbb_root_path . 'includes/functions.' . $phpEx); +				$this->filesystem->phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE); +			} +			catch (\phpbb\filesystem\exception\filesystem_exception $e) +			{ +				// Do nothing  			} - -			phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);  			$return_value = true;  		} diff --git a/phpBB/phpbb/cache/driver/memcached.php b/phpBB/phpbb/cache/driver/memcached.php index a7da22d7e8..7d66759ec2 100644 --- a/phpBB/phpbb/cache/driver/memcached.php +++ b/phpBB/phpbb/cache/driver/memcached.php @@ -65,10 +65,10 @@ class memcached extends \phpbb\cache\driver\memory  			$this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);  		} -		foreach (explode(',', PHPBB_ACM_MEMCACHE) as $u) +		foreach (explode(',', PHPBB_ACM_MEMCACHED) as $u)  		{  			preg_match('#(.*)/(\d+)#', $u, $parts); -			$this->memcache->addServer(trim($parts[1]), (int) trim($parts[2])); +			$this->memcached->addServer(trim($parts[1]), (int) trim($parts[2]));  		}  	} diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 0b0e323e3d..cc03804705 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -25,9 +25,9 @@ abstract class memory extends \phpbb\cache\driver\base  	*/  	function __construct()  	{ -		global $phpbb_root_path, $dbname, $table_prefix; +		global $phpbb_root_path, $dbname, $table_prefix, $phpbb_container; -		$this->cache_dir	= $phpbb_root_path . 'cache/'; +		$this->cache_dir	= $phpbb_container->getParameter('core.cache_dir');  		$this->key_prefix	= substr(md5($dbname . $table_prefix), 0, 8) . '_';  		if (!isset($this->extension) || !extension_loaded($this->extension)) @@ -81,9 +81,10 @@ abstract class memory extends \phpbb\cache\driver\base  	*/  	function tidy()  	{ -		// cache has auto GC, no need to have any code here :) +		global $config; -		set_config('cache_last_gc', time(), true); +		// cache has auto GC, no need to have any code here :) +		$config->set('cache_last_gc', time(), false);  	}  	/** @@ -203,7 +204,7 @@ abstract class memory extends \phpbb\cache\driver\base  	{  		// Remove extra spaces and tabs  		$query = preg_replace('/[\n\r\s\t]+/', ' ', $query); -		$hash = md5($query); +		$query_id = md5($query);  		// determine which tables this query belongs to  		// Some queries use backticks, namely the get_database_size() query @@ -244,14 +245,13 @@ abstract class memory extends \phpbb\cache\driver\base  				$temp = array();  			} -			$temp[$hash] = true; +			$temp[$query_id] = true;  			// This must never expire  			$this->_write('sql_' . $table_name, $temp, 0);  		}  		// store them in the right place -		$query_id = sizeof($this->sql_rowset);  		$this->sql_rowset[$query_id] = array();  		$this->sql_row_pointer[$query_id] = 0; @@ -261,7 +261,7 @@ abstract class memory extends \phpbb\cache\driver\base  		}  		$db->sql_freeresult($query_result); -		$this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl); +		$this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl);  		return $query_id;  	} diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php index eda774491c..eaeb529918 100644 --- a/phpBB/phpbb/cache/driver/redis.php +++ b/phpBB/phpbb/cache/driver/redis.php @@ -137,6 +137,10 @@ class redis extends \phpbb\cache\driver\memory  	*/  	function _write($var, $data, $ttl = 2592000)  	{ +		if ($ttl == 0) +		{ +			return $this->redis->set($var, $data); +		}  		return $this->redis->setex($var, $ttl, $data);  	} diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index 56727c2ad5..8a4366fed1 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -141,6 +141,7 @@ class service  				$icons[$row['icons_id']]['img'] = $row['icons_url'];  				$icons[$row['icons_id']]['width'] = (int) $row['icons_width'];  				$icons[$row['icons_id']]['height'] = (int) $row['icons_height']; +				$icons[$row['icons_id']]['alt'] = ($row['icons_alt']) ? $row['icons_alt'] : '';  				$icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];  			}  			$this->db->sql_freeresult($result); @@ -301,7 +302,6 @@ class service  		{  			switch ($this->db->get_sql_layer())  			{ -				case 'mssql':  				case 'mssql_odbc':  				case 'mssqlnative':  					$sql = 'SELECT user_id, bot_agent, bot_ip | 
