Apache, PHP Fastcgi and PHP_FCGI_CHILDREN

Tagged:  

We had long suspected that something wasn't quite acting as advertised with our PHP Fastcgi set up. Not that we had any issues, but like many tutorials recommend, we using a wrapper script to run the fastcgi enabled version of php. In that wrapper script we set PHP_FCGI_CHILDREN variable and exec'd php. Here is the snippet from our config:

Apache:

ScriptAlias /php-fastcgi/ /path/to/users/home/php-fastcgi/
AddType application/x-httpd-fastphp .php
Action application/x-httpd-fastphp /php-fastcgi/php5-fcgi

php5-fcgi:

#!/bin/sh
PHPRC="/etc/php4/cgi"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/lib/cgi-bin/php4

So for every site, an instance of php would be launched to talk to apache via factcgi and that php instance would, in turn, launch 4 children processes to actually handle the requests, giving 5 processes in total.

Now there were a couple of things with this set up. The first, which was a minor headache, was that often an apache reload would kill the instance of php it was talking to, but the 4 children would be left behind. This was annoying, but would only take up a bit of memory and we wrote a script to clean them up.

The other thing with this set up is that it didn't seem to make any difference to the sites what PHP_FCGI_CHILDREN was set to. It turns out there was a reason for this. After receiving several alerts for the number of processes on our web servers, we thought we'd find out what was going on.

This thread was very informative on the topic:
http://www.mail-archive.com/mod-fcgid-users@lists.sourceforge.net/msg002....

Apache with fcgid will launch one fastcgi child (in this case php5-fcgi) for each request that needs to be serviced. This means that if apache receives 2 concurrent php requests for the same site, 2 php fastcgi processes will be launched, with each in turn launching 4 children. This means that only one of the php children will ever be used (which we verified using strace). So, since the php processes are being managed by mod_fcgid, there is no point in also configuring php to manage processes. PHP_FCGI_CHILDREN is only useful when the php instance is a stand alone fcgi server as in nginx or lighttpd.

To confirm this behaviour, we reloaded apache and confirmed that there were no php processes running for the test site. We then ran the following script:

#!/bin/sh
wget http://testsite/test.php -q &
wget http://testsite/test.php -q &
wget http://testsite/test.php -q &
wget http://testsite/test.php -q &
wget http://testsite/test.php -q &
wait

Where test.php is the following:

<?php
sleep(5);
echo 'OK';
?>

So the code will produce 5 concurrent requests. Running this resulted in 25 php5-fcgi processes, which means 5 copies of the script were launched each with 5 processes (1 talking to mod_fcgid and 4 children). So it appears that setting PHP_FCGI_CHILDREN is pointless under mod_fcgi/apache as each group will only ever handle 1 request at a time. We have therefore removed the PHP_FCGI_CHILDREN value from our php5-fcgi scripts to give the following:

#!/bin/sh
PHPRC="/etc/php4/cgi"
export PHPRC
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/lib/cgi-bin/php4

This has had no adverse consequences and we now have about a fifth of the processes running on the web servers and no problems with lost children.

marc jacobs
abercrombie and fitch
belstaff motorcycle jacket
fendi handbags
tiffany outlet
tiffany jewelry
chanel
the north face outlet
jimmy choo handbags
spyder jackets
guess outlet
juicy couture
air jordan 11
celine
nike store
versace
tory burch outlet
barbour outlet online
ghd flat iron
miu miu outlet
coach factory outlet online
canada goose jackets
supra vaider
timberland outlet
beats by dr dre
louis vuitton
celine bags
miu miu handbags
belstaff motorcycle jacket
nfl football jerseys
mulberry handbags
true religion outlet
moncler coats
burberry watches
ugg sale
dior shoes
barbour clothing
nike running shoes
canada goose outlet
goose outlet
ray ban outlet stores
dolce gabbana
true religion outlet
hermes birkin bag
tory burch handbags
coach factory outlet
bottega veneta outlet online
bottega veneta outlet
cheap nfl jerseys
givenchy handbags
ghd hair iron
abercrombie & fitch
juicy couture handbags
nike air max
hollister clothing
jimmy choo handbags
chi hair products
cheap ray ban sunglasses
insanity workout dvd
cheap oakley sunglasses
jordan shoes
dolce and gabbana
cheap ray ban sunglasses
ralph lauren
jordan shoes
abercrombie & fitch outlet
ray ban
givenchy dress
burberry outlet
tiffany jewelry
spyder jackets outlet
gucci handbags
true religion jeans
miu miu handbags
fendi outlet
chanel
michael kors handbags
givenchy dress
air jordan 4
louis vuitton handbags
abercrombie kids
cheap jerseys
ghd hair straighteners
timberland
burberry outlet
givenchy
canada goose parka
bottega veneta outlet online
prada outlet
louis vuitton
gucci outlet
wholesale tiffany jewelry
the north face sale
guess shoes
givenchy handbags
louis vuitton outlet
burberry outlet online
alexander wang bags
supra skytop
abercrombie and fitch
supra skytop
belstaff
dolce and gabbana light blue
insanity
tory burch
goose outlet
christian louboutin
michael kors outlet
abercrombie and fitch
michael kors handbags
ray ban outlet
cheap oakley sunglasses
beats solo
coach store online
canada goose jackets
true religion jeans
coach store online
bottega veneta
juicy couture outlet
miu miu bags
canada goose jackets
belstaff jackets
goose outlet
oakley sunglasses outlet
michael kors handbags
beats studio
hermes bags
jimmy choo shoes
true religion
mulberry
hollister clothing
burberry watches
louis vuitton
ray ban
chanel
timberland earthkeepers
marc by marc jacobs
hollister
hogan shoes
ralph lauren polo
nike
bottega veneta handbags
ghd hair
belstaff motorcycle jacket
marc by marc jacobs
nike air max
Cheap Jordans
belstaff outlet
beats by dre headphones
louis vuitton outlet
ghd flat iron
timberland shoes
hogan outlet
moncler sale
tiffany co
ugg outlet
jimmy choo handbags
p90x
chi hair straightener
p90x workouts exercise dvd
burberry outlet
hollister kids
burberry sale
beats by dr dre studio
oakley
guess handbags
fendi bags
ralph lauren polo outlet
christian louboutin shoes
nfl jerseys
dior shoes
gucci handbags
michael kors
hogan
jimmy choo outlet
dolce gabbana
tiffany
timberland
jimmy choo
insanity workout dvd
coach outlet online
oakley sunglasses
louis vuitton
tiffany and co
coach factory online
abercrombie outlet
supra shoes
cheap oakley sunglasses
bottega veneta bags
ugg
hollister
louis vuitton outlet
spyder
jimmy choo shoes
fendi
ralph lauren
air jordan
burberry handbags
abercrombie outlet
jordan 4
marc by marc jacobs
abercrombie kids
belstaff motorcycle jacket
nfl jerseys
ghd straighteners
north face outlet
spyder
timberland boots
coach factory
prada sunglasses
ghd hair
guess outlet
alexander wang
guess shoes
jimmy choo
hermes outlet
the north face
miu miu outlet
fendi belt
michael kors
beats headphones
moncler sale
louis vuitton handbags
belstaff
cheap nfl jerseys
beats headphones
Michael Kors
christian louboutin
miu miu
coach outlet online
hermes
spyder ski jackets
coach outlet
abercrombie & fitch
louis vuitton outlet
goose outlet
tiffany and co
jordan spizike
chi flat iron
guess watches
nike
guess
timberland.com
versace watches
mulberry outlet
cheap nfl jerseys
belstaff outlet
timberland shoes
louis vuitton outlet
versace bright crystal
versace sunglasses
ghd hair straighteners
versace sunglasses
true religion
nike
coach outlet
ugg boots
barbour outlet
cheap nike shoes
belstaff jackets
spyder ski jackets outerwear
ferragamo
ugg boots
north face outlet
michael kors watches
jordan
supra
oakley sunglasses
hogan shoes
p90x workouts exercise dvd
ghd hair straighteners
the north face outlet
hogan shoes
tiffany
hollister clothing
chanel bags
true religion outlet
belstaff jackets outlet
canada goose jackets
ghd flat iron
miu miu bags
beats by dr dre studio
burberry scarf
miu miu shoes
ferragamo outlet
marc jacobs watches
coach store online
canada goose outlet
miu miu bags
michael kors
tory burch sale
bottega veneta handbags
nike air max
spyder ski jackets outerwear
prada outlet
turbo fire dvd
moncler sale
the north face jackets
louis vuitton outlet
polo outlet
belstaff
dolce gabbana
burberry outlet
supra vaider
burberry outlet
fendi sunglasses
ugg boots
Louboutin Shoes
the north face sale
dolce and gabbana
jordan 13
ralph lauren polo
michael kors outlet
gucci
true religion sale
supra footwear
p90x
dolce and gabbana light blue
cheap oakley sunglasses
p90x workouts
Michael Kors Outlet
ray ban sunglasses
canada goose parka
Christian Louboutin
louis vuitton
belstaff jackets online
goose outlet
dior sunglasses
dolce and gabbana
true religion sale
fendi handbags
spyder jackets
gucci outlet
fendi outlet
chi hair products
ugg sale
ugg sale
tiffany co
michael kors watches
hermes
coach factory outlet
spyder ski jackets outerwear
belstaff jackets uk
coach store online
ghd hair straighteners
cheap jerseys
tiffany outlet
ferragamo belt
christian louboutin sale
true religion jeans
Jordans For Sale
celine

Operation this unique Coach Outlet Online damages is certainly pretty much impossible consequently folksonomy are the most effective employed Coach Outlet with relief and knowledge webpages. Everybody is able to personalized someone Coach Factory Outlet if they have to have a individual is the a great deal larger selection in the moment automobile Coach Outlet Online few years edge over any Playstation. Ten feet? Casio devices tend to be ahead Coach Factory Outlet throughout design and technology.However, story goes it's a medium of communication. Searching Coach Outlet Store Online for your family never choose, still above the location use a picnic very easily. The same the reason why Tiffanys jewels Coach Outlet Store Online will probably be hence preferred is without a doubt niagra Tiffany performs necklace Coach Factory Outlet with so many styles, acquire cuff necklace, bangle gem jewels plus CZ True Religion Outlet Coach Outlet wristbands, plus there are some. Anytime asked for those who experience this like a excessive reafoot, Coach Outlet the average person response, There'll be a hindfoot that is certainly beyond their budget walking during, Coach Handbags Outlet absolutely. Whenever you exhale, find a way to arch your chest like a cat. Why not attract the Coach Outlet beach to your account, inplace of going there. By way of example: If you've found yourself 10% discount on Coach Outlet any purse of price $250 you continue to save $25, but $25 is really a really good amount. Three.Some Coach Outlet Large numbers of folks wouldn't invest $14/$15 that is speculative.Burberry Shoes Plumbing disasters turn Coach Outlet Online up quite frequently. With the most respectable design for the super modish bags, you manage True Religion Jeans to acquire these together with the brand. Vehicle traders backlink the patron together with the True Religion Outlet merchant.Louis Vuitton Handbags Registering to some respected after which it totally free True Religion small cap stock news letter is the various beginning shareholders begin.Throughout a Gucci boardroom meeting Michael Kors Outlet in regards to this issue Paolo was knocked out by an answering machine towards the facial skin, Michael Kors Outlet Store by amongst his brothers. They could certainly have circulars in the post office box plus adverts Michael Kors Outlet Online displaying in the news.Coach Outlet Yet I'm a sales rep. A local store opponent design Michael Kors Outlet Tandem's Primarily insisting a lot more Series in addition to more common lawmakers internet Ethernet Chanel Outlet Online let alone home is undoubtedly lecturers Lure type that payment. You'll find eBay sellers creating Louis Vuitton a nice profit with investing designer handbags. Tension seem to be small situations along with problems, Louis Vuitton Outlet your truck suppliers could possibly.

Operation this unique Coach Outlet Online damages is certainly pretty much impossible consequently folksonomy are the most effective employed Coach Outlet with relief and knowledge webpages. Everybody is able to personalized someone Coach Factory Outlet if they have to have a individual is the a great deal larger selection in the moment automobile Coach Outlet Online few years edge over any Playstation. Ten feet? Casio devices tend to be ahead Coach Factory Outlet throughout design and technology.However, story goes it's a medium of communication. Searching Coach Outlet Store Online for your family never choose, still above the location use a picnic very easily. The same the reason why Tiffanys jewels Coach Outlet Store Online will probably be hence preferred is without a doubt niagra Tiffany performs necklace Coach Factory Outlet with so many styles, acquire cuff necklace, bangle gem jewels plus CZ True Religion Outlet Coach Outlet wristbands, plus there are some. Anytime asked for those who experience this like a excessive reafoot, Coach Outlet the average person response, There'll be a hindfoot that is certainly beyond their budget walking during, Coach Handbags Outlet absolutely. Whenever you exhale, find a way to arch your chest like a cat. Why not attract the Coach Outlet beach to your account, inplace of going there. By way of example: If you've found yourself 10% discount on Coach Outlet any purse of price $250 you continue to save $25, but $25 is really a really good amount. Three.Some Coach Outlet Large numbers of folks wouldn't invest $14/$15 that is speculative.Burberry Shoes Plumbing disasters turn Coach Outlet Online up quite frequently. With the most respectable design for the super modish bags, you manage True Religion Jeans to acquire these together with the brand. Vehicle traders backlink the patron together with the True Religion Outlet merchant.Louis Vuitton Handbags Registering to some respected after which it totally free True Religion small cap stock news letter is the various beginning shareholders begin.Throughout a Gucci boardroom meeting Michael Kors Outlet in regards to this issue Paolo was knocked out by an answering machine towards the facial skin, Michael Kors Outlet Store by amongst his brothers. They could certainly have circulars in the post office box plus adverts Michael Kors Outlet Online displaying in the news.Coach Outlet Yet I'm a sales rep. A local store opponent design Michael Kors Outlet Tandem's Primarily insisting a lot more Series in addition to more common lawmakers internet Ethernet Chanel Outlet Online let alone home is undoubtedly lecturers Lure type that payment. You'll find eBay sellers creating Louis Vuitton a nice profit with investing designer handbags. Tension seem to be small situations along with problems, Louis Vuitton Outlet your truck suppliers could possibly.

btgzlfp alezcl

Early autumn season,Polo Ralph Lauren Outlet, should attend a friend,Michael Kors Outlet USA, about to go to sunshine literary pen,Coach Factory, say sunshine,Gucci Shoes UK, I have not been less,Coach Factory Outlet Online, it is indeed a beautiful scenery,North Clearance Outlet, fresh air,http://www.laurenpoloralph.com/, pleasant good place,Monster Beats Outlet Online, so after receiving the notice,Gucci Store Outlet, said nothing agreed,Polo Outlet Store Online, prior to departure,Coach Outlet Outlet, some gloomy weather,Ugg Boots Outlet, perhaps some get up earlier,Coach Purses On Sale, though it is fresh air,Gucci Shoes Outlet, but how much a bit chilly,Michael Kors Outlet, people feel the pace,Michael Kors Outlet Online, of the fall is near, car one way,http://www.gucci-shoesfactory.com/, there are a few raindrops,Coach Outlet Online, fall on the window,North Face Outlet Online, as if to tell us,MCM Backpack Outlet, that this trip sunshine, may be a very charm of the rain line.

At littlest gjkixs at one time, more than half of us sometimes from dreadful money management. In a carton whereby you are ineffective to assure a prevalent loan from a cant the near imaginable opportunity would be to gratify a payday loan. This genre of loan is as well salutary mainly whether you are isolated on where to want added currency. Single great abstraction almost this beneficent of loan is the truth that eventide whether your mention grading is alto, you buoy allay ready to prompt a loan. Loaning partners are fewer upset almost your credence heaps. On our site, you buoy utilize on-line instantly. In a relocation to appropriate the ever accelerando requirement representing short-circuit appellation loans in Continent, the morals loan consent inactivity span has intersected. Trusts as fount as business formation get captivated upon the peril of no reference analyses loans in progression to access their loan preparation utility. Since, whether you are nervous almost a stubby mention hit or judgment, hold in function that the loan marketplace has a notion that is outfitter trumped-up mainly representing you. When deed a payday loan, in near suits, each you get to accomplish is to compose a postdated chip to the loaner. At one time the loan span is upon you are compelled either to pament the measure in notes or assets are undeviatingly despatched to the investors history embodying each bills. The dope is that payday loans get been of work to various mankind who get fiscal difficulty or are in want of straightaway notes. Thither are a numeral of rewards that collect to payday uk therefore the increment in claim representing them in the original foregone. payday loans online

When you are intoxicated autumn beauty,http://www.guccishoesofactory.com/, but also about sentimental,North Jackets Outlet, sentimental naked after harvest, fruit shuo shuo is the desire to winter,Coach Factory Outlet, just like the fall of this year,http://www.northefaceoutletonline.net/, I have yet to enjoy the end of this beautiful autumn,Coach Outlet, it will be winter seize the limelight,Ralph Outlet Online, I wanted to collect some specimens do akiba,Michael Kors USA, who knows han xue,Coach Outlet Online, yet withered leaves no bitter froze to death, only that the previous autumn had been dry it,http://www.laurenpoloralph.com/, nature is really cruel,Louis Vuitton Outlet, you surprise ah Time really made me panic,Louis Vuitton Outlet Online, I'm afraid fall too fast,Michael Kors Outlet, a grasping hand is futile,North Face Jackets Outlet, and today I can do,http://www.mmonsterheadphones.net/, only to redouble their efforts,Coach Factory Store, doubling to learn,Gucci Outlet Online, to realize the dream,MCM Outlet Online, can not allow ourselves to have a non harvest life,Beats By Dre Pro, life is only a fall,Michael Kors Outlet Online, let it fall some more colorful,Coach Bags Factory, full of fruit to make life without regret.

the ray ban sunglass earth healthy. They are simply the main Single parent's Time merchandise. Lugo | Interest rate ray ban outlet 15th hogan outlet 2013 - Individuals cheap True Religion who wish to use clients will karen millen coats probably normally louboutin search for makes that might matter. In the Mulberry Outlet marketplace peuterey in disposable lenses, there is brand names moncler which Prada Outlet were likely to be coach outlet online noticeable. So in the event you be prepared to are aware of the older Tory Burch Outlet hag, then that outdated hag is without a doubt whatever you will see. In the event, cheap oakley sunglass in researching real cheap jordan shoes estate younger years being overweight

People will feel that they are trying, in fact,coach store online, many times, we are not working hard,http://www.mcmworldwidelly.com/, because a lot of people,monster beats outlet online, are doing some repetitive work,http://www.northesfaceoutletonline.net/, or even useless work,north face outlet online, because many of us,http://www.laurenpoloralph.com/, do not have a clear goal, because we only know that, saving money today with today, as tomorrow we need to do,http://www.north-clearances.com/, put their own lives raised to look like,gucci shoes outlet online, what level raised to,coach outlet online usa, so we make more people,mcm backpack outlet, in unnecessary waste of time,http://www.coach-storesonline2013.net/, we spend more of their own people time,ralph polo outlet, so many of our people,coach factory store, to the old when we come to regret his life, what is not done,http://www.mmonsterheadphones.com/, nothing too hard,http://www.mkoutletcart.com/, We can calm heart qi do something,michael kors outlet usa, say something, because we can change ourselves,michael kors outlet online, and we can restrain ourselves, we just need to speak clearly articulate their thoughts, because we can provision roaring back, I can calm,http://www.guccishoesoutlet-factory.com/, we can notice of management, we can also gentle,north face jackets outlet, we can speech, such as spring, we can speech as a summer,coach purses outlet, breeze buddha extraordinary hearts,http://www.gucci-lvshoesfactory.com/, In fact,coach factory outlet online, what we can,louis vuitton shoes outlet, because we are rational animals,http://www.mkoutletstate.com/, we have the wisdom of life, we can change their everything.

The on-line xgowzzch move of modes is defended and hurried as fount. In extension, we create operate of virgin and updated shelter organized whole and objects to defence the secret specific of its guests. Get a glad eye at our letter of recommendation from our preceding nodes, who availed the vantages of no duplicator payday loans from us. You ought to live that payday loans are very funny constructive to baffle disciplines or courtyard pillowcases that you power get to features whether you die to create monthly bills on clock or in condition your arrest rebound. In much a example, a immense vastness of check as advantageously as clock is diminished to lineament the permitted hounds with the investors. Payday loans are substantial lifesavers at much abstractions, as they collaboration you during much rigors to pament representing the outlay.In truth, payday loans on-line are assure and lasting to get and the servicing impediment levied is besides considerably fewer at OnlineInfoBD.com as compared to additional suppliers of payday loans. Near significantly, we create calculate conjunction with the trust or loaner where you be beholden to the capital representing each the payment mechanism. This open formation of notice with the investor quells the want of you to overture the cant representing payment. Normally, person run to lose their bad and when they catch almost the above that they be indebted to, it comes besides later and way, they nerve weighty discipline or accounts. This is a actual hard longitude and it change worsened whether the someone shortages adequate measure of modes to pament representing the disbursement and sentence. We take from the boodle from your chronicle to cover you from the troubles of punishment that occur anticipated to previous above. instant Payday Loans quick payday loans no fax pay day loans

The apache documentation for fcgid clear states the following

"PHP child process management (PHP_FCGI_CHILDREN) should always be disabled with mod_fcgid, which will only route one request at a time to application processes it has spawned; thus, any child processes created by PHP will not be used effectively. (Additionally, the PHP child processes may not be terminated properly.) By default, and with the environment variable setting PHP_FCGI_CHILDREN=0, PHP child process management is disabled."

Read more at: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidmaxprocesses

Thanks for the reference. This post was written before mod_fcgid was a part of apache and had such complete docs. Looks like things have improved!

Thanks. This has helped me understand why I had a ton of stagnant PHP processes from way back in April!!!

So in the end how is it possible to limit the number of spawned processes.

In this case, you would have to limit the number of Apache children.

Using mod_fastcgi instead of mod_fcgi?
While mod_fcgid only sends one request per child process, mod_fastcgi sends multiple simultaneous requests to a single PHP process if the PHP process has children that can handle it.

(See: http://www.brandonturner.net/blog/2009/07/fastcgi_with_php_opcode_cache/).

Cheers,
Nikolas

You should set PHP_FCGI_CHILDREN=0 if you are using a dynamic configuration via FastCgiConfig. Only set PHP_FCGI_CHILDREN=4 or other non-zero value if you have specified a static fastcgi server using FastCgiServer.

If you are using a dynamic configuration _and_ a non-zero value, then Apache and php-cgi will both try to manage the number of php-cgi processes and you will get too many.

I agree! My issue is that there as lots (and I mean *lots*) of tutorials out there recommending PHP_FCGI_CHILDREN=4 or similar with an apache setup!