Question

In my php error log for about a months ago i see an error

PHP Fatal error:  Out of memory (allocated 524288) (tried to allocate 311296 bytes) public_html/index.php on line 347

It's strange because the error says that it allocated only 524288 which would be 512 KB the error is the same as always and occurs only on this line of script and i get about 10-20 times this error per day

in index.php i have included 4-5 script and on that line (ln 347) there is which only returns some css codes and There is no infinite loop

I've read a lot of topics and changed mempry_limit to 256M and added RLimitMEM 173741824 247483648 and MaxRequestsPerChild 9000 In apache

In my tests i use a code like this

if($_SERVER['REMOTE_ADDR'] == $my_IP) 
{
  var_dump(memory_get_usage());
  var_dump(memory_get_peak_usage());
}

in on the beginning and the end of script which results:

int(729812) int(741124)  -  int(915952) int(953968)  

I have a vps with php 5.3.22 installed and with 1.5 GB ram where most of times 200-500 mb is free and i have something about 20,000 hits per day maybe more and server load sometimes goes to 8 for a little period of times

the website is very fast and there is nothing wrong with speed

in the root there are 3-4 php files which is accessible by public too but in error log i dont see them although they dont have that hits as index.php

in my localhost i install x-debug and win cache grind and when i profile the index.php script i see nothing wrong in there too

On this vps i've also install wordpress which gives errors too but at least the amount of memory he could allocated is more, one of the error is like this:

PHP Fatal error:  Out of memory (allocated 9961472) (tried to allocate 7 bytes) in /public_html/blog/wp-includes/canonical.php on line 157

for the wordpress i'v set memory_limit 256M in htaccess

I have also install livezilla which gives errors too

PHP Fatal error:  Out of memory (allocated 524288) (tried to allocate 77824 bytes) in public_html/support/_lib/functions.global.inc.php on line 520

for the livezilla i'v also set memory_limit 256M in htaccess

I should mention that in my vps i've hosted 5-6 other websites

And one time i faced with this error in phpMyAdmin that says:

PHP Fatal error:  Out of memory (allocated 524288) ...

again only allocated 524288

Iv restarted apache over and over but nothing changes

Could the line number in error log be wrong due to including other scripts before that line?

Could it be the Cpu issue?

I'm struggling with this error about 2 months and i don't know what to do else any idea?

Was it helpful?

Solution 2

setting configuration for prefork in apache worked!

OTHER TIPS

It's very likely that your webserver is miss configured regarding memory consumption, allowed concurrent requests and available memory.

Evaluate your logs to see how many and what concurrent requests you have on such peaks. You might stress your server with ab to reproduce those situations. 1.5 GB ram for 20k hits a day just feels wrong. Check your webserver configuration how many concurrent requests are allowed and how big a fork might grow. I'm quiet certain they will easily eat up those 1.5 GB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top