Does anyone run php as a cgi application? I am asking because a friend has setup my server with fastcgi + php5, but I am not sure what the advantages of it are besides having a smaller memory foot print, being more secure, and allowing each vhost to have it's own php config. Also, I have a few issues with it occasionally where it uses up alot of resources and spikes cpu/mem usage, but I cannot figure out why. I get errors along the lines of "incomplete headers fastcgi. It usally happens when mysql is restarted, possibly due to php still having open connection with mysql, but I am not sure. Does anyone here use fastCGI with php5? If so, what’s your reason? Also, I would like to understand how it works - but there are very, I mean very, few guides that explain how to set it up or how it actually works. Any feedback would be greatly appreciated.
I saw a few benchmarks a while back comparing apache2, apache1, thttpd and lighttpd. Fastcgi is usually used with lighttpd to run perl and php scripts, its not used often with apache but I could be wrong since all I have done so far is run apache1.3 I think if you use apache it might very well be pointless except for saving ram and maybe loading less modules at startup.
I use it. Compared to mod_php it's probably gonna be slower. But compared to CGI, it's 100x better. It's not a smaller memory footprint, per se. I mean, there's a lot of overhead when every request to a php script causes you to load up php, process the script, tear down php. With FastCGI, PHP gets loaded up when Apache starts, and stays up, processing scripts. This leads to other advantages like, persistent mysql connections, caching compiled scripts with eAccelerator. These actually use up more ram, but saves on CPU. FastCGI doesn't really save ram, because binaries that are frequently loaded will be cached by linux. FastCGI keeps them running, so their memory footprint is in use 100% of the time, if you are only getting 5 hits an hour on regular CGI, you are actually using less memory by using regular CGI than you would be with FastCGI... as a total usage over time. But it does take more CPU to keep loading up and tearing down the php processor over and over. I think it all depends on the setup, as I understand it, mod_php requires a php processor in each Apache child. If you have a lot of them, it would use more memory, but you can concurrently process more requests than FastCGI than if you had 10 apache children and 2 FastCGI processes running. But, the only reason I can see to use FastCGI over mod_php is security. Chroots, suexec... etc... here is a faq : http://www.seaoffire.net/fcgi-faq.html You may want to investigate AppArmor, because I've been hearing good things about it, like it could fix the security problems present with mod_php, but eliminate the need to use CGI at all. Your memory spikes when mysql restarts, are most likely mysql. They probably don't have much to do with fastcgi, except that mysql's query cache gets emptied. So queries take longer, and it has to rebuild the cache, using up more memory and CPU, if your queries are very slow (i.e. not very efficient scripts and queries) it could start lagging PHP.
Thanks for the FAQ list. I will read thru it. As for my issue. Whenever mysql is restarted my sysystem crawls and I usally have to reboot the box. It becomes unresponsive at times. My code is pretty good so I doubt it's lagging php.
Best thing to do, just watch top. "top d 1" See what's happening, something is eating up CPU/Mem. The only thing to do really is reset it and see. My guess is that it's Mysql itself. I can restart mysql running fastcgi, but it does lag initially for a while, while it rebuilds the cache. I'd just see where your system load is sitting. It's not unusual for something to use up mem and cause a cascade of problems.
How much traffic is hitting your box during these resets? and how many php-cgi processes do you have? And do you have a phpinfo() I can look at?