Link to home
Start Free TrialLog in
Avatar of stephaneeybert
stephaneeybert

asked on

Fatal error: Allowed memory size of 8388608 bytes exhausted

Dear all,

I get the following message when running my application on my web hotel.

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 18660 bytes) in /home/httpd/vhosts/thalasoft.net/httpdocs/engine/modules/news/includes.php on line 12

But it works fine on my own computer.

Any idea..?

Kind Regards
Stephane
Avatar of minichicken
minichicken

Try at the top of your page:

ini_set("memory_limit", "50M"); //allow more memory

try that just to see
Avatar of Roonaan
Well, probably your memory limits on your hosted server are set lower than on you local system. This isn't unusual actually. What is unusual is the fact that your script exceeds this limit, which tells something about the efficiency it is coded by.

You are taken 8 mb with you script. Would require much of memory if you'd have only 50 simultaneous users!

use unset() to clear arrays from memory you do no longer use. you can use unset to destory objects also.

Regards

-r-
Re: minichicken.

A point made by Cobol Dinosaur just yesterday was that EE is supposed to educate users. Telling them how to increase memory allowance is a bad practice to my opinion. Even if it's 'just to see'.

-r-
ASKER CERTIFIED SOLUTION
Avatar of minichicken
minichicken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stephaneeybert

ASKER

But when testing my application on my own web server, I get no such message. And the memory limit is also 8M.

Is there a PHP function to print out the allocated memory for a script?

I thank you all for your comments.

I gave the points to minichicken for I did what he advised me to do.

I increased the memory limit in the php.ini file to 20Mb.

I understand Roonan's point here.

But the problem came from using the ioncube encoder on my php files.

After reporting the issue to the ioncube technical support they came back with the same advice, namely to increase the memory limit.

Which I did and it now works fine.

I understand that I still need to see why my application is using so much memory.

I'll try to clean up the include tree of my php files.

Would anyone know about any php functions returning the used memory for a client request?

I would like to have an idea of how much memory my application is using here and what load it can sustain.

Cheers

Stephane
Depends on the version of php you are using:
memory_get_usage() can be used for such things (http://www.php.net/memory_get_usage)

Regards

-r-
Thanks!
When running (Ubuntu) Linux, the possibility to increase the memory available to PHP may not work if the package php5-suhosin is installed. This package aims to make your PHP installation more secure, and one effect of this is that scripts are somewhat limited in what they can do in terms of system settings.

As for setting the memory, I have created a function to do this:

function fncChangeMemoryAvailabletoPHP($intDesiredAmountOfMemoryAvailableToPHP = "2048M"){                // Done; works, but needs cleaning up
	// This function can be used to pre-emptively deal with possible memory problems
	// Method: set PHP memory limit for this session.
	// NOTE: Expressed in MegaBytes, HAS TO BE FOLLOWED BY THE CHARACTER "M", e.g. "2048M"!
	// Note that the "128M" setting does not do anthing here,
	// this is just to get a reading on the current setting. Without a value supplied there
	// an error message follows, so it has to be included even if it is not used?
	$intPHPsCurrentMemoryLimit = ini_set('memory_limit', "128M");
	// NOW, the $intDesiredAmountOfMemoryAvailableToPHP value SHOULD set PHP memory limit.
	ini_set('memory_limit', $intDesiredAmountOfMemoryAvailableToPHP); // Set the value
	$strPHPsCurrentMemoryLimit = ini_set('memory_limit', $intDesiredAmountOfMemoryAvailableToPHP); // Read out the value set above
	if($strPHPsCurrentMemoryLimit == $intDesiredAmountOfMemoryAvailableToPHP){
	    $strPHPsCurrentMemoryLimit = ini_set('memory_limit', $intDesiredAmountOfMemoryAvailableToPHP);
	}else{
		$strPHPsCurrentMemoryLimit = ini_set('memory_limit', $intDesiredAmountOfMemoryAvailableToPHP);
		$strMessageToBePrinted = "Attempt to set PHP's memory limit to ".$intDesiredAmountOfMemoryAvailableToPHP."B";
		$strMessageToBePrinted = $strMessageToBePrinted." FAILED! PHP's memory limit is at present: ".$strPHPsCurrentMemoryLimit;
		$strMessageToBePrinted = $strMessageToBePrinted." <br />Since the new memory limit for PHP could not be applied, PHP might run out of memory later!";
		$my_pid = getmypid();
		error_log("MEMORY USAGE (% KB PID ): ".`ps -eo%mem,rss,pid | grep $my_pid`); 
		echo $strMessageToBePrinted;
	}
	return $intPHPsCurrentMemoryLimit;
}

Open in new window

I don't think suhosin sits on my server.

But thanks for the tip anyway!