How to know for sure if FastCGI is being used to run php scripts

前端 未结 8 917
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 14:51

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 m

相关标签:
8条回答
  • 2020-12-13 15:53

    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');
    }
    
    0 讨论(0)
  • 2020-12-13 15:54

    php_sapi_name() or PHP_SAPI, both work.

    http://php.net/manual/en/function.php-sapi-name.php

    <?php
        if (php_sapi_name() != 'cgi-fcgi'){
            echo 'I knew fastcgi wasn\'t working.';
        }else{
            echo 'Holy crap, something worked for once.';
        }
    
    0 讨论(0)
提交回复
热议问题