Joomla caching and memory usage

Discussion regarding Joomla! 1.5 Performance issues.
Locked
User avatar
ahmad
Joomla! Guru
Joomla! Guru
Posts: 903
Joined: Fri Apr 07, 2006 4:02 pm
Location: Egypt
Contact:

Joomla caching and memory usage

Post by ahmad » Wed Apr 17, 2013 12:12 pm

First of all, I am not looking for an answer saying "Check your PHP memory limit" or "You need to add more memory" or these kind of stuff ...

I am sitting on a HUGE machine, with 8GB of rams 512MB of it is assigned as memory limit. I always get an out of memory error on one single line :

File: libraries/joomla/cache/storage/file.php
Line: 62

Code: Select all

function get($id, $group, $checkTime)
	{
		$data = false;

		$path = $this->_getFilePath($id, $group);
		$this->_setExpire($id, $group);
		if (file_exists($path)) {
			$data = file_get_contents($path);			
			if($data) {
				// Remove the initial die() statement
				$data	= preg_replace('/^.*\n/', '', $data);     // This is the line where the error occur
			}
		}

		return $data;
	}
As you can see the line uses a preg_replace to remove the first line in the cache file which is always :

Code: Select all

<?php die("Access Denied"); ?>
My question is, although it is a simple process (removing the first line from the file content) could it consume a lot of memory if the initial $data is huge? if so, what's the best way to work around that issue? I don't mind having the cache files without that die() line I can take of security and block direct access to the cache files.

Am I wrong?
Thanks for your collaboration
Last edited by ahmad on Wed Apr 17, 2013 1:21 pm, edited 2 times in total.

User avatar
ahmad
Joomla! Guru
Joomla! Guru
Posts: 903
Joined: Fri Apr 07, 2006 4:02 pm
Location: Egypt
Contact:

Re: Joomla caching and memory usage

Post by ahmad » Wed Apr 17, 2013 12:41 pm

I am getting interesting thoughts from fellows on StackOverflow about using substr to avoid the memory hungry preg_replace() , like this:

Code: Select all

$data = substr($data, strpos($data, '?>') + 3);

almooj-craig
Joomla! Guru
Joomla! Guru
Posts: 500
Joined: Mon Aug 11, 2008 3:05 pm

Re: Joomla caching and memory usage

Post by almooj-craig » Fri Apr 19, 2013 4:10 am

Ahmad,

I do not add the die line when the page is originally saved, then I don't need to remove it later. If you have the cache files outside of the root directory then there isn't any additional security problem.

There is also a regexp that swaps the cached security token with the users token which I think would take much longer to process. I don't cache pages that include forms, so there is never a token so I don't use regexp to strip it out.

I actually use gzencode to store the data, then if their browser can accept gzip you just set the correct headers and echo it out. That way Apache does not need to deflate the data on the fly, it's already done and it takes less storage space. If they do not accept gzip then you need to gzdecode it back to a normal string before you echo it out.

Craig


Locked

Return to “Performance - Joomla! 1.5”