WordPress.org

Plugin Directory

Changeset 192787 for health-check


Ignore:
Timestamp:
01/11/10 18:19:26 (4 years ago)
Author:
Denis-de-Bernardy
Message:

don't merely verify that mod_rewrite exists: check that it actually works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • health-check/branches/alpha/hc-tests/server-configuration.php

    r192747 r192787  
    371371        if ( !$is_apache && !HEALTH_CHECK_DEBUG ) 
    372372            return; 
    373         $message = sprintf(__( 'Your Webserver does not have <a href="%s">Apache functions</a>. These make it easier for WordPress to detect the availability of Apache modules such as mod_rewrite. Please contact your host to have them fix this.', 'health-check' ), 'http://php.net/manual/en/ref.apache.php'); 
    374         $passed = $this->assertTrue(function_exists('apache_get_modules'), 
    375                                     $message, 
    376                                     HEALTH_CHECK_RECOMMENDATION ); 
    377  
    378         if ( !$passed ) { 
    379             $message = sprintf(__( 'WordPress failed to detect Apache\'s mod_rewrite module on your Webserver, from lack of proper means to detect it. WordPress assumes it is present, but <a href="%s">Apache functions</a> would be needed to ensure proper detection. Please contact your host to have them fix this.', 'health-check' ), 'http://php.net/manual/en/ref.apache.php'); 
    380         } else { 
    381             $message = sprintf(__( 'WordPress failed to detect Apache\'s mod_rewrite module on your Webserver. <a href="%s">Fancy permalinks</a> will not work without it, unless you prepend your permalink structure with /index.php.', 'health-check' ), 'options-permalink.php'); 
    382         } 
    383         $this->assertTrue(  apache_mod_loaded('mod_rewrite'), 
    384                             $message, 
    385                             HEALTH_CHECK_RECOMMENDATION ); 
     373         
     374        $test_dir = rtrim(wp_cache_get('test_dir', 'health_check'), '/'); 
     375        $test_url = rtrim(wp_cache_get('test_url', 'health_check'), '/'); 
     376        $http_api = wp_cache_get('http_api', 'health_check'); 
     377        $checked = false; 
     378        switch ( true ) { 
     379        default: 
     380            if ( !$test_dir || !$test_url || !$http_api || !wp_mkdir_p($test_dir . '/health-check') ) 
     381                break; 
     382            // we might be able to test that mod_rewrite actually *works* 
     383            $test_path = parse_url($test_url); 
     384            $test_path = $test_path['path']; 
     385            $htaccess = <<<EOS 
     386 
     387RewriteEngine On 
     388RewriteBase $test_path/health-check/ 
     389RewriteCond %{REQUEST_FILENAME} !-f 
     390RewriteRule ^ $test_path/health-check/test.txt [L] 
     391 
     392EOS; 
     393            // a reliable file lock is only around in PHP 5.1 
     394            // and there's little point in acquiring any 
     395            if ( !( $fp = @fopen("$test_dir/health-check/.htaccess", 'w') ) 
     396                || !@fwrite($fp, $htaccess) || !@fclose($fp) ) 
     397                break; // bail 
     398 
     399            if ( !( $fp = @fopen("$test_dir/health-check/test.txt", 'w') ) 
     400                || !@fwrite($fp, 'OK') || !@fclose($fp) ) 
     401                break; // bail 
     402 
     403            $res = wp_remote_get("$test_url/health-check/"); 
     404 
     405            @unlink("$test_dir/health-check/.htaccess"); 
     406            @unlink("$test_dir/health-check/test.txt"); 
     407            @rmdir("$test_dir/health-check/"); 
     408 
     409            $checked = true; 
     410 
     411            $message = sprintf(__('Your Webserver does not have mod_rewrite, or WordPress cannot enable its custom rewrite rules using a .htaccess file. This will prevent <a href="%s">fancy URLs</a> from working on your site without prepending them with /index.php. Please contact your host to have them fix this.', 'health-check'), 'options-permalink.php'); 
     412            $importance = HEALTH_CHECK_RECOMMENDATION; 
     413            $this->assertTrue(  ( $res['response']['code'] == 200 ) && ( $res['body'] == 'OK' ), 
     414                                $message, 
     415                                HEALTH_CHECK_RECOMMENDATION ); 
     416        } 
     417         
     418        if ( !$checked || HEALTH_CHECK_DEBUG ) { 
     419            $message = sprintf(__('WordPress failed to detect mod_write on your Webserver. It might be around... or not. If can prevent <a href="%s">fancy URLs</a> from working on your site without prepending them with /index.php. Please contact your host to have them fix this.', 'health-check'), 'options-permalink.php'); 
     420            $this->assertTrue(  apache_mod_loaded('mod_rewrite'), 
     421                                $message, 
     422                                HEALTH_CHECK_INFO ); 
     423        } 
    386424    } 
    387425} 
Note: See TracChangeset for help on using the changeset viewer.