Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What PHP memory_limit (php.ini) do you suggest for a VPS with 256M RAM ?

I'm using Ubuntu 10 + Apache2 + Php5 thanks

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

There's no generic "recommended" setting, as it's completely dependent on what you're doing with your PHP code. I'd recommend starting with it set to 64M and then if you have problems with it bumping up against that limit, then slowly raise it. Keep in mind that you'll need to restart apache after changing this value before it will take effect.

share|improve this answer
    
Could you give me some examples of "what I'm doing with my PHP code" ? So I know how to set it ? –  Patrick Nov 4 '10 at 17:14
    
How much RAM PHP will need depends on, well, however much RAM your PHP code needs to execute. Just set it to 64M as suggested. Chances are good that that's all you'll ever need, but if you do run into problems, it's trivial to bump it up. –  EEAA Nov 4 '10 at 17:15
add comment

With only 256MB ram you should consider starting with 16MB and increasing as necessary.

If you have a leaking application you would have only four requests to that application before the RAM is wasted. Keep in mind that, whatever you are trying, 256MB RAM is not very much.

Though if your application isn't leaky than you should put your eye on the apache configuration because every apache child potentially uses PHP.

To keep the amount of RAM which is being used as stable as possible you might want PHP to be run as fastcgi. If you want to get all out of available memory go this way:

Measure the amount of RAM needed for your application and how much hits you get. Configure Apache to spawn the absolute minimum of children necessary to serve the clients. And spawn just as many fastcgi processes to serve the apache children.

share|improve this answer
    
Can i see the used RAM from terminal ? Second after second ? –  Patrick Nov 4 '10 at 17:26
    
free -mt | /usr/bin/awk 'NR == 2 {print $3}' The while loop is up to you. –  pacey Nov 4 '10 at 17:32
add comment

This is all about concurrency.

If it's OK for you to have only a single PHP request going on, then it may consume something between 64-128 MB at will.

If your site has lots of visitors, then your server needs to have more simultaneous PHP processes and the memory usage grows. Sure, some of that memory might be shared among the processes, but with scripts like fetching a huge dataset from a database will need that privately. That will grow your memory needs like there's tomorrow.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.