Plugin Directory

Changeset 945064


Ignore:
Timestamp:
07/08/2014 05:10:03 PM (12 years ago)
Author:
eoigal
Message:
  • Update test connection to make new API call to test endpoint to verify connection
  • Demote server IP checks to debug data only as not reliable on their own to identify connection problem, and showing warning notice serves only to confuse some users
  • Add more debug, like WP and PHP version along with test connection results to help debug connectivity tickets
File:
1 edited

Legend:

Unmodified
Added
Removed
  • akismet/trunk/class.akismet-admin.php

    r943192 r945064  
    544544    // Check connectivity between the WordPress blog and Akismet's servers.
    545545    // Returns an associative array of server IP addresses, where the key is the IP address, and value is true (available) or false (unable to connect).
    546     public static function check_server_connectivity() {
    547         $test_host = 'rest.akismet.com';
     546    public static function check_server_ip_connectivity() {
     547       
     548        $servers = $ips = array();
    548549
    549550        // Some web hosts may disable this function
    550         if ( !function_exists('gethostbynamel') )
    551             return array();
    552 
    553         $ips = gethostbynamel( $test_host );
    554         if ( !$ips || !is_array($ips) || !count($ips) )
    555             return array();
    556 
    557         $api_key = Akismet::get_api_key();
    558 
    559         $servers = array();
    560         foreach ( $ips as $ip ) {
    561             $response = Akismet::verify_key( $api_key, $ip );
    562             // even if the key is invalid, at least we know we have connectivity
    563             if ( $response == 'valid' || $response == 'invalid' )
    564                 $servers[$ip] = true;
    565             else
    566                 $servers[$ip] = false;
    567         }
     551        if ( function_exists('gethostbynamel') ) { 
     552           
     553            $ips = gethostbynamel( 'rest.akismet.com' );
     554            if ( $ips && is_array($ips) && count($ips) ) {
     555                $api_key = Akismet::get_api_key();
     556               
     557                foreach ( $ips as $ip ) {
     558                    $response = Akismet::verify_key( $api_key, $ip );
     559                    // even if the key is invalid, at least we know we have connectivity
     560                    if ( $response == 'valid' || $response == 'invalid' )
     561                        $servers[$ip] = 'connected';
     562                    else
     563                        $servers[$ip] = $response ? $response : 'unable to connect';
     564                }
     565            }
     566        }
     567       
    568568        return $servers;
    569569    }
    570 
    571     // Check the server connectivity and store the results in an option.
    572     // Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
    573     // Returns the same associative array as check_server_connectivity()
    574     public static function get_server_connectivity( $cache_timeout = 86400 ) {
     570   
     571    // Simpler connectivity check
     572    public static function check_server_connectivity($cache_timeout = 86400) {
     573       
     574        $debug = array();
     575        $debug[ 'PHP_VERSION' ]         = PHP_VERSION;
     576        $debug[ 'WORDPRESS_VERSION' ]   = $GLOBALS['wp_version'];
     577        $debug[ 'AKISMET_VERSION' ]     = AKISMET_VERSION;
     578        $debug[ 'AKISMET__PLUGIN_DIR' ] = AKISMET__PLUGIN_DIR;
     579        $debug[ 'SITE_URL' ]            = site_url();
     580        $debug[ 'HOME_URL' ]            = home_url();
     581       
    575582        $servers = get_option('akismet_available_servers');
    576         if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
    577             return $servers;
    578 
    579         // There's a race condition here but the effect is harmless.
    580         $servers = self::check_server_connectivity();
    581         update_option('akismet_available_servers', $servers);
    582         update_option('akismet_connectivity_time', time());
    583         return $servers;
     583        if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false ) {
     584            $servers = self::check_server_ip_connectivity();
     585            update_option('akismet_available_servers', $servers);
     586            update_option('akismet_connectivity_time', time());
     587        }
     588           
     589        $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' );
     590       
     591        $debug[ 'gethostbynamel' ]  = function_exists('gethostbynamel') ? 'exists' : 'not here';
     592        $debug[ 'Servers' ]         = $servers;
     593        $debug[ 'Test Connection' ] = $response;
     594       
     595        Akismet::log( $debug );
     596       
     597        if ( $response && 'connected' == wp_remote_retrieve_body( $response ) )
     598            return true;
     599       
     600        return false;
     601    }
     602
     603    // Check the server connectivity and store the available servers in an option.
     604    public static function get_server_connectivity($cache_timeout = 86400) {
     605        return self::check_server_connectivity( $cache_timeout );
    584606    }
    585607
     
    785807
    786808    public static function display_status() {
    787         $servers    = self::get_server_connectivity();
    788         $fail_count = count( $servers ) - count( array_filter( $servers ) );
    789         $type       = '';
    790 
    791         if ( empty( $servers ) || $fail_count > 0 )
     809        $type = '';
     810
     811        if ( !self::get_server_connectivity() )
    792812            $type = 'servers-be-down';
    793 
    794         if ( !function_exists('gethostbynamel') )
    795             $type = 'missing-functions';
    796813
    797814        if ( !empty( $type ) )
Note: See TracChangeset for help on using the changeset viewer.