How to know for sure if FastCGI is being used to r

2019-01-22 04:30发布

I have a hosted site and I'm having trouble configuring Joomla (running Joomla + php + mySQL on IIS7 + win server 2008). I have a similar configuration running on a local machine (Joomla + php + mySQL on IIS7 + vista x64), so I was at least able to follow instructions showed in various tutorials on how to set this up.

This symptom with the hosted site is that I can't turn on any SEO settings in Joomla (not even the first setting, "Search Engine Friendly URLs"). I get either 404 (file not found) or the URL appears correctly rewritten but it's always the home page's content that is displayed. I had a similar issue on my home machine and it turns out to have been because I wasn't using FastCGI to host php, so I decided to investigate that on the hosted site.

Anyway, I noticed in the web.config file of the directory hosting joomla on the hosted site the following line:

<add name="Plesk_Handler_3522909676" path="*.php" verb="*" modules="IsapiModule" scriptProcessor="c:\program files (x86)\parallels\plesk\additional\pleskphp5\php5isapi.dll" resourceType="Either" />

From past experience, I know that php has some issues when not running under fastCGI. I noticed the web.config in the root folder used the following line instead:

<add name="Plesk_Handler_0286090609" path="*.php" verb="*" modules="CgiModule" scriptProcessor="c:\program files (x86)\parallels\plesk\additional\pleskphp5\php-cgi.exe" resourceType="Either" /> 

I copied that in the web.config in the joomla directory, and got different behavior... but still not working. If I load a .php file in the joomla directory that runs phpInfo(), under Server API it says CGI/FastCGI . Is that positive confirmation that FastCGI is being used? Why does the handler in the web config point to modules="CgiModule" instead of modules="FastCgiModule" (I'm not even sure that exists, but I just find the mention of CgiModule suspicious).

It's a hosted site, so as far as I know I don't have access to ApplicationHost.config file...

8条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-22 04:34

You should see a referenced to it from

<?php
phpinfo();
?>

Server API = CGI/FastCGI

查看更多
不美不萌又怎样
3楼-- · 2019-01-22 04:37

Here's a simple test:

  1. Create a phpinfo.php file with

 <?php phpinfo(); ?> 

inside;

  1. Request http://yoursite.com/phpinfo.php/foobar?foo=bar

  2. Check the output of phpinfo and look for _SERVER["REQUEST_URI"].

If this variable is missing, then CGI is used. If the variable is present and correctly set to /phpinfo.php/foobar?foo=bar, then either ISAPI or FastCGI is used. Look near the top of the output for Server API; it should be set to either ISAPI (which means ISAPI is being used) or CGI/FastCGI (which means FastCGI is being used, since we already ruled out CGI).

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-22 04:37

Unfortunately, the checking \_SERVER["REQUEST_URI"] didn't work for me. Using CGI or FastCGI, it always displayed /phpinfo.php/foobar?foo=bar.

Neither did seeing if Server API = CGI/FastCGI was set - that only tells you what interfaces the compiled version of php supports, not what is being used. However, I found another method that may work more reliably.

Plonk a file in place called phpinfo.php containing the text: <? php phpinfo(); ?>

Check for the variable \_ENV["REDIRECT_HANDLER"]:
If it is set to php5-fastcgi (or something else fastcgi-ish) the request most probably went through FastCGI. If it is set to application/x-httpd-php (or I assume something other than the above), you are using CGI.

However, a surefire way is by running a little test. You need the ab (Apache Bench) tool for this.
Both with and without CGI, run this from another machine:

ab -c 100 -n 1000 http://yourdomain.com/path/phpinfo.php

Check the line Time taken for tests:. On my box at least, accessing my VPS over a 1.3Mbps ADSL connection, FastCGI completely maxed it out, while with CGI was only able to fill half of it.

Hope this helps.

查看更多
虎瘦雄心在
5楼-- · 2019-01-22 04:39

You can use (on centos) apachectl -M, you'll show what modules are enabled:

apachectl -M:

file_cache_module (shared) mem_cache_module (shared) version_module (shared) fastcgi_module (shared)

查看更多
成全新的幸福
6楼-- · 2019-01-22 04:42

This worked for me.

/**
 * return phpinfo() results as an array
 *
 * @credit http://php.net/manual/en/function.phpinfo.php#106862
 * @param void
 * @return array
 */
function phpinfo_array(){
    ob_start();
    phpinfo();
    $info_arr = array();
    $info_lines = explode("\n", strip_tags(ob_get_clean(), '<tr><td><h2>'));
    $cat = 'general';
    foreach($info_lines as $line){
        preg_match('/<h2>(.*)<\/h2>/', $line, $title) ? $cat = preg_replace('/\s+/', '_', strtolower(trim($title[1]))) : null;
        if(preg_match('/<tr><td[^>]+>([^<]*)<\/td><td[^>]+>([^<]*)<\/td><\/tr>/', $line, $val)){
            $subcat = preg_replace('/\s+/', '_', strtolower(trim($val[1])));
            $info_arr[$cat][$subcat] = $val[2];
        } elseif(preg_match('/<tr><td[^>]+>([^<]*)<\/td><td[^>]+>([^<]*)<\/td><td[^>]+>([^<]*)<\/td><\/tr>/', $line, $val)){
            $subcat = preg_replace('/\s+/', '_', strtolower(trim($val[1])));
            $info_arr[$cat][$subcat] = array('local' => $val[2], 'master' => $val[3]);
        }
    }
    return $info_arr;
}


// output proper response code
$phpinfo = phpinfo_array();
$configure = (@isset($phpinfo['general']['configure_command'])) ?: null;

// properly account for FastCGI
if ($configure && preg_match('/--enable-fastcgi/', $configure)){
    // fastcgi response
    header('Status: 403 Access is forbidden');
} else {
    // http response
    header('HTTP/1.0 403 Access is forbidden');
}
查看更多
别忘想泡老子
7楼-- · 2019-01-22 04:44

Make sure things are set up initially to where the script fails completely when fastcgi isn't running. Then you'll know, when it works, that fastcgi daemon is the reason.

查看更多
登录 后发表回答