fcgi

Hello Jo
I have a a few qestions an suggestions for fcgi. I wonder why there should be 4 children for every site visitor. Becaus when you got a lot of connections and domains this consumes a lot of memory for every single visitor. I commented PHP_FCGI_CHILDREN out and had no problem with this configuration. So every user has got one single php5-cgi process now.

#!/bin/sh
PHPRC=$PWD/…/etc/php5
export PHPRC

PHP_FCGI_CHILDREN=4

export PHP_FCGI_CHILDREN
SCRIPT_FILENAME=$PATH_TRANSLATED
export SCRIPT_FILENAME
exec /usr/bin/php5-cgi

another question :wink: why are there phpx.fcgi files in the home/domain/public_html folder and in the home/domain/fcgi-bin/, why are they needed in both folders? And how can i set a standard conf file for creating new domains. Becaus i don’t want to comment PHP_FCGI_CHILDREN=4 out every time i switch my php versions or when i create new domains :wink:
by the way do you think there is potential for tuning the etc/apache/enabled-modules/fcgid.conf file a bit? Maybe Then the /etc/webmin/virtual-server/fcgiclear.pl is not needed anymore :slight_smile:

<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
SocketPath /var/lib/apache2/fcgid/sock
IPCConnectTimeout 20
DefaultInitEnv RAILS_ENV production
IdleTimeout 60
ProcessLifeTime 6000
MaxProcessCount 32
DefaultMaxClassProcessCount 2
IPCConnectTimeout 6
IPCCommTimeout 6
</IfModule>

i found this config when searching the net i think that woul be interesting. The standard fcgid.conf looks like that:

<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
SocketPath /var/lib/apache2/fcgid/sock
IPCConnectTimeout 20
</IfModule>

i don’t know maybe thats all stupid an shit what im talkin about but i could not find any “serious” documentations about that config files :slight_smile:

regards Martin

Hey Martin,

That’s a lot of comments! We’ll take them one at a time.

I’ll first say, though, that fcgi support is still pretty new. Changes might be sane, as we’re working from documentation on the web rather than any serious experimental evidence. So, as we get more real world data, these bits might change.

I wonder why there should be 4 children for every site visitor. Becaus when you got a lot of connections and domains this consumes a lot of memory for every single visitor. I commented PHP_FCGI_CHILDREN out and had no problem with this configuration. So every user has got one single php5-cgi process now.

It’s not 4 children per site visitor. It’s 4 per script being wrapped. These are long-running processes that the fcgid connects to in sequence in order to serve requests rapidly.

They are not very demanding, with regard to memory usage, as they will share a large percentage of memory used for libraries and such. I dunno what the balance is, and it’ll depend on the application, but it’s probably over 75% shared.

We also tend to assume a relatively large memory system, where performance is more important than saving a few kilobytes per user. It does add up, and if you’re hosting 1000 websites on a single box (and allowing them to run scripts), you’ll definitely want to shave memory usage everywhere possible.

But I believe 4 children is a sane compromise (bigger sites may want more, smaller my be able to get by with less–but it is useful for concurrency).

why are there phpx.fcgi files in the home/domain/public_html folder and in the home/domain/fcgi-bin/, why are they needed in both folders?

This was a temporary fix for a broken mod_fcgid package on Ubuntu. I rolled out a fixed package, but some of those fcgi wrappers might still exist. I believe it is safe to delete them, assuming none of your Apache configuration sections are calling them. If they are still being generated with the latest version of Virtualmin, it’s probably a bug.

And how can i set a standard conf file for creating new domains. Becaus i don't want to comment PHP_FCGI_CHILDREN=4 out every time i switch my php versions or when i create new domains ;)

Good question. It’s not currently configurable, as it’s something that is so easily broken and the defaults are pretty sane for the vast majority of users.

I’ve filed a wish in the tracker to make this one knob changeable.

http://www.virtualmin.com/index.php?option=com_flyspray&Itemid=82&do=details&task_id=3168

Maybe Then the /etc/webmin/virtual-server/fcgiclear.pl is not needed anymore :)

No, that one is to address one or more bugs that lead to thousands of fcgi wrappers running in a non-working state. It’s not a configuration issue.

Joe,

And how can i set a standard conf file for creating new domains. Becaus i don't want to comment PHP_FCGI_CHILDREN=4 out every time i switch my php versions or when i create new domains ;)
Good question. It's not currently configurable, as it's something that is so easily broken and the defaults are pretty sane for the vast majority of users.

WRONG! :wink: Just go to VirtualMin > Server Settings > Server Templates > Default Settings > PHP Wrapper
You enter the info for your wrapper either under: FastCGI wrapper for PHP 4 or FastCGI wrapper for PHP 5 like this:

#!/bin/sh
PHPRC=$PWD/…/etc/php4
export PHPRC
PHP_FCGI_CHILDREN=1
export PHP_FCGI_CHILDREN
exec /opt/local/bin/php4-cgi

Tony

Hehehe…I was just about to post to this thread, as Jamie pointed this out to me in the bug that I filed about it.

You’re the best in the biz, Tony, no matter what they say about you. :wink:

:wink: I take this as a compliment. :stuck_out_tongue:

Thanks Tony it works!
Is something like that also possible for the php.ini :wink:

Martin,

Is something like that also possible for the php.ini

I think so… check:

VirtualminPro > System Settings > Server Templates > Apache Website

Scroll there all the way down and you should find this:
"PHP configuration variables for scripts"

This table can be used to enter PHP configuration settings that will be added to the web virtual host of any server that has a third-party script installed. It can be useful for increasing memory limits or making other site-specify PHP config changes to satisfy script requirements.

So all you do is this:
Under "Template PHP configuration file" you give it your "default" php.ini as a template so to speak. And then enter the things that VM should add to it into the fields at "PHP configuration variables for scripts". I have not tried it yet myself but it should work fine I think.

Tony

How can I override this on the user account level? When I make the changes as you suggested nothing new shows up in /home/account/fcgi-bin/php5.fcgi file. And, when logged in as root or user owner you can’t remove or modify that file.

The php5.fcgi file has the "immutable" attribute set for security reasons.

If you’d like to edit it outside of Virtualmin, you’d need to run this as root:

chattr -i php5.fcgi

At that point, you can make what changes you want – then you should re-add the immutable attribute:

chattr +i php5.fcgi

Using Virtualmin’s default configuration I did some performance tests using Apache Benchmark (ab2). It kept the machine too busy to serve other web sites in a reasonably time frame once one of the web sites got stressed by ab2. Well, ab2 may put a machine to it’s theoretically limit and real usage patterns probably are different in not beaing that demanding. Nevertheless I decided to only allow 2 PHP processes per user. I did set this globally by editing /etc/apache2/mods-available/fcgid.conf that way:

[code:1]
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
IPCConnectTimeout 20
DefaultMaxClassProcessCount 2

MaxProcessCount 100

MaxRequestsPerProcess 500
</IfModule>
[/code:1]
[ul]
[li]DefaultMaxClassProcessCount: The max processes per User/Virtual Server.[/li]
[li]MaxProcessCount: When set it limits the running PHP processes in total.[/li]
[li]MaxRequestsPerProcess: Set this to avoid a potential error in PHP’s handling of FastCGI requests which are over it’s default limit of 500.[/li]
[/ul]

Get more information about fcgid settings here: http://fastcgi.coremail.cn/doc.htm

Using this settings the serving of web pages on my shared hosting server feels snappy even if one of the web sites get "slashdotted".

This way you don’t get the maximum out of Apache and PHP. It is a setup for “standard” web hosting which allows many web sites behave friendly on a shared server. If running a high demanding web site I rather would serve it using mod_php instead of fcgid on a dedicated box.