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.

I have installed php5 in ubuntu and WordPress. It can run after installed. But after few days I've found there are lots of process and occupied a lot of memories. I try to use

ps -aux | grep www-data

and found about 30 processes like this.

www-data  5066  0.0  0.0 131664   780 ?        S    16:20   0:00 /usr/sbin/php5-fpm --fpm-config /etc/php5/fpm/main.conf

I tried to

kill -9 pid

and it didn't work, more process appears again. So could you tell me how to kill them safely and I don't want to my vps' memory occupied by it.

share|improve this question

migrated from stackoverflow.com Nov 4 '11 at 8:00

This question came from our site for professional and enthusiast programmers.

3 Answers 3

and it didn't work, more process appears again

Really? While I'd expect more processes to appear the one you killed should go away.

If you want to stop all of these then shutdown the daemon, I don't know how it's configured on your machine, but here I'd do....

/etc/init.d/php-fpm stop

But htat's not the way to fix the problem of "I've found there are lots of process and occupied a lot of memories". You should start by doing proper traffic analysis and profiling the code.

share|improve this answer

Try here, I think its the same problem :)

http://serverfault.com/questions/89616/how-to-stop-www-datas-apache-processes

"Apache running as www-data is the default in Debian Lenny. You might be confusing a single 'parent' apache process (running as root) with apache 'children' doing HTTP request processing (running as www-data). Both 'parent' and 'children' processes should look like they were started with /usr/sbin/apache2 -k start (when you ps aux | grep apache), and the only difference is the process owner.

To control init startup scripts you could use sudo sysv-rc-conf (sudo aptitude install sysv-rc-conf if you don't have it - it is just an easy curses-like Perl wrapper for init scripts)." -Chronos

So each process is child process dealing with http requests, if yo really want to kill them either kill the process with sudo kill PID or maybe /usr/sbin/apache2 -k stop.

Tom

share|improve this answer
    
There is also one process that belongs to root and not www-data. This one is needed to bind to port 80 but will not actually do anything else for safety reasons. –  Christoph Grimmer-Dietrich Nov 2 '11 at 8:51
    
i do not want to stop nginx or apache ,just think the memory it used may be too large.could you give me a solution that can optimize it or let the memory it occupied be fewer? –  yudun1989 Nov 2 '11 at 9:56
    
Apache is never going to be super memory efficient. If you want to really minimize your memory usage, maybe use another web server such as lighttp lighttpd.net. If your hell-bent on streamlining Apache, maybe try wiki.joyent.com/display/gen/Tuning+Apache. –  Xleedos Nov 2 '11 at 11:32
    
Also take not of the bottom of this page, soporte.ideasmultiples.com/…. Basically you can tune your Apache to have less spare children, this will save memory. Hope this helps :) –  Xleedos Nov 2 '11 at 11:35

There is 100% nothing wrong with what you are seeing. PHP is a module being run by Apache which is controlled by the user www-data. What you are seeing is normal behavior. And the bulk of adjustments to me made to improve performance are connected to Apache configs & not so much PHP settings.

If you want to better control this behavior, there are two places to make adjustments.

1. Adjust the PHP Memory Limit: Open up your php.ini file which should be located in /etc/php5/apache2/php.ini and edit the option called memory_limit. It should be set to 64M or 32M. But that is basically the MAX limit for memory any PHP process—which is tied to each Apache2 process (see below)—can use. So if you run WordPress & it wants to run any process with 32M RAM, no problem. If it needs more the script will fail & your Apache2 error log located at /var/log/apache2/error.log will fill with errors.

2. Adjust Your Apache Config to Suit Your Needs: Since PHP is a module running in Apache, the more Apache processes you have running the more memory will be eaten up. If you have a standard Apache2 install open up this file & look around: /etc/apache2/apache2.conf. Specifically here are the settings I always adjust in a standard install.

  • Timeout: This is the timeout between a request being made by the client to the server & the server fulfilling that request. In my experience the setting of 300 seconds (5 minutes) is too high. I adjust this to 120.
  • KeepAlive: I always keep this on as it helps Apache use memory & resources better. It basically means an Apache child process won't kill itself if a client is still requesting content. That way one process can flow data & then safely die after it has done it's job.
  • MaxKeepAliveRequests: This is directly connected to KeepAlive. And I adjust this based on server needs. For development environments I keep this low. Let's say 3 or 4. For production environments I tend to feel KeepAlive is only useful for about 1/3 of connections. So I set this to about 24 or 32. But it memory is a concern, I would keep this low as the more KeepAlive processes you have running the more clients you have running & the more RAM you have used per process.
  • KeepAliveTimeout: This is basically a measurement of how fast one can load a page on your site. Think about it: Why keep a connection alive past the time it takes for a client to get the content for one page? In my experience a setting of 2 seconds to 5 seconds is good. But when it veers up to 5 seconds to render a page, it means that something is really choking the underlying system. So to me that is a sign to re-evaluate code & clean up resource intensive coding.

    Next go to the mpm_prefork_module area. This is how I setup my development environment; this is for a low traffic site.

<IfModule mpm_prefork_module>
  StartServers           8
  MinSpareServers        8
  MaxSpareServers        8
  ServerLimit           16
  MaxClients            16
  MaxRequestsPerChild 2000
</IfModule>

Basically this sets all the limits & parameters for a basic Apache install. I believe each parameter should be self explanatory, but here is my breakdown.

  • StartServers: How many child servers startup immediately under Apache.
  • MinSpareServers: The minimum amount of child servers to keep in reserve.
  • MaxSpareServers: The maximum amount of child servers to keep in reserve.
  • ServerLimit: The top limit on the how many child servers can exist.
  • MaxClients: The maximum amount clients that can exist at any given moment.
  • MaxRequestsPerChild: This setting helps kill of child processes after a certain number of requests. This helps prevent memory leaks because technically child processes can run on forever until the next Apache2 restart. A safeguard I like to have in place so I can sleep at night even when a developer deploys sloppy code.

Hope this helps!

share|improve this answer
1  
No, it's not running as a php module. Tweaking the apache config will have no direct impact on it. –  symcbean Mar 24 '13 at 23:45
    
Welp, I got nothing else. Hopefully someone can learn from my answer anyway. –  JakeGould Mar 25 '13 at 1:14

Your Answer

 
discard

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