Do you support FastCGI and PHP OPcache?
Our servers support the FastCGI protocol to speed up scripts for busy sites. FastCGI provides a way to keep frequently-run script files loaded in memory so that the script is already preloaded and initialized the next time it’s used. We also used software called “OPcache” to further speed up scripts run under FastCGI.
This can make some scripts (particularly PHP scripts) run much more quickly. For example, a simple "Hello World" PHP script can easily run more than 1,000 times a second using FastCGI (compared to 20 times per second without). In most cases, using FastCGI for PHP scripts is as fast as using mod_php, without the security drawbacks.
For new accounts, we use FastCGI by default for PHP scripts. You can use our “My Account” control panel to enable or disable FastCGI:
- Login to the control panel
- Click PHP Settings
- Check (or uncheck) the Use FastCGI checkbox
- Click Save Settings
The rest of this page has more information about FastCGI and OPcache:
- Disabling FastCGI for certain directories
- Using custom FastCGI programs
- Which FastCGI module is installed?
- OPcache
Disabling FastCGI for certain directories
We recommend FastCGI for all PHP scripts. However, a very small handful of very old PHP scripts don't work properly with FastCGI.
If you want to use FastCGI for most of your PHP scripts, but you also have one or more individual directories containing scripts that need to be run without FastCGI, you can disable FastCGI for an entire directory. To do that, add this line to a .htaccess file in the directory:
AddHandler application/x-httpd-php .php
This tells the Apache web server to run PHP scripts in that directory without FastCGI.
Using custom FastCGI programs
To use a custom FastCGI program (i.e., not a PHP script), install it like any other compiled script (including making it “executable”, aka “mode 0755”), but make sure that the name ends with ".fcgi
" instead of the normal ".cgi
".
For example, you might install a FastCGI program named "program.fcgi
" that looks like this:
#!/usr/bin/perl use FCGI; my $count = 0; my $request = FCGI::Request(); while($request->Accept() >= 0) { print("Content-type: text/html\r\n\r\n", ++$count); }
That program would then be accessible as:
http://www.example.com/program.fcgi
Alternately, you can force a file with a ".cgi" name extension to be run under FastCGI with this .htaccess file line:
AddHandler fastcgi-script .cgi
(This only works if the CGI script has been coded to support FastCGI, of course.)
Which FastCGI module is installed?
We use mod_fcgid
with some custom modifications. We've found mod_fcgid
to be superior to the alternative mod_fastcgi
— in particular, mod_fcgid
works properly with dynamically launched PHP scripts, but mod_fastcgi
does not.
In practice, users should notice no difference between the two modules. Properly written FastCGI applications will work with either mod_fastcgi
or mod_fcgid
.
OPcache
We automatically enable OPcache to speed up PHP scripts. This speeds them up even more when using FastCGI.
You can view or change your site’s PHP version by doing this:
- Login to the control panel
- Click PHP Settings
If you need to disable OPcache for some reason, add this line to your site’s php.ini settings on that page:
opcache.enable = 0
Copyright © 2000-2024 Tiger Technologies LLC