Plugin Directory

Changeset 2077511


Ignore:
Timestamp:
04/30/2019 04:30:12 AM (7 years ago)
Author:
wsec1
Message:

0.4 Added caching machanism for score using wpcron

Location:
super-host-speed-benchmark/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • super-host-speed-benchmark/trunk/readme.txt

    r2076811 r2077511  
    43430.3 Fixed SQL error in benchmark
    4444
     450.4 Added caching machanism for score using wpcron
     46
  • super-host-speed-benchmark/trunk/shsb.php

    r2076811 r2077511  
    44* Plugin URI: https://superhostspeed.com/
    55* Description: Test and benchmark the speed of your hosting provider, based on the speed of their mysql database, which tends to be the main cause of Wordpress being slow on some hosts. A score of less than 40 is bad and a score of more than 100 is very good. Scores will be reported to our server in future versions so you can compare speeds with others. See Tools/Speed Benchmark
    6 * Version: 0.3
     6* Version: 0.4
    77* License: GPL2+
    88* Copyright 2019 Anthony Walker
     
    1717add_action( 'admin_menu', 'shsb_add_admin_menu' );
    1818add_action( 'admin_init', 'shsb_settings_init' );
     19
     20
    1921
    2022
     
    127129add_action('admin_menu', 'shsb_add_pages');
    128130
    129 // action function for above hook
    130 function shsb_add_pages() {
    131        // Add a new submenu under Tools:
    132     add_management_page( __('Speed Benchmark','menu-test'), __('Speed Benchmark','menu-test'), 'manage_options', 'speedbenchmark', 'shsb_tools_page');
    133    
    134 }
    135 // shsb_tools_page() displays the page content for the Test Tools submenu
    136 function shsb_tools_page() {
    137    
     131function shsb_calculate_score()
     132{
    138133    global $wpdb;
    139    
    140     echo "<h2>" . __( 'Calculating benchmark....', 'menu-test' ) . "</h2>";
    141 
    142 $charset_collate = $wpdb->get_charset_collate();
     134    $charset_collate = $wpdb->get_charset_collate();
    143135
    144136$table_name=$wpdb->prefix ."speedtest202";
     
    191183   
    192184    $score=$score/1000;
     185   
     186    $options = get_option( 'shsb_settings' );
     187   
     188    if ($options['shsb_checkbox_field_2']==0)
     189    {
     190    $url="https://superhostspeed.com/benchmark.php?score=$score&h=".urlencode($options['shsb_text_field_0'])."&o=".urlencode($options['shsb_text_field_1'])."&host=".gethostname()."&ip=".$_SERVER['SERVER_ADDR']."&httphost=".$_SERVER['HTTP_HOST'];
     191    //echo $url;
     192    $r=file_get_contents($url);
     193    }
     194
     195return $score;   
     196   
     197}
     198
     199// action function for above hook
     200function shsb_add_pages() {
     201       // Add a new submenu under Tools:
     202    add_management_page( __('Speed Benchmark','menu-test'), __('Speed Benchmark','menu-test'), 'manage_options', 'speedbenchmark', 'shsb_tools_page');
     203   
     204}
     205// shsb_tools_page() displays the page content for the Test Tools submenu
     206function shsb_tools_page() {
     207   
     208    global $wpdb;
     209   
     210    $shsb_score_time=get_option( "shsb_score_time",0);
     211    if ($shsb_score_time==0 || time()-$shsb_score_time>60*60*12)
     212    {
     213   
     214    echo "<h2>" . __( 'Calculating benchmark....', 'menu-test' ) . "</h2>";
     215   
     216    $score=shsb_calculate_score();
     217
     218    add_option( 'shsb_score', $score, '', 'no' );
     219    add_option( 'shsb_score_time', time(), '', 'no' );
     220    }
     221    else
     222    {
     223        $score=get_option( "shsb_score",0);
     224    }
    193225   
    194226    $purl= plugins_url();
     
    258290EOT;
    259291
    260     $options = get_option( 'shsb_settings' );
    261    
    262     if ($options['shsb_checkbox_field_2']==0)
    263     {
    264     $url="https://superhostspeed.com/benchmark.php?score=$score&h=".urlencode($options['shsb_text_field_0'])."&o=".urlencode($options['shsb_text_field_1'])."&host=".gethostname()."&ip=".$_SERVER['SERVER_ADDR']."&httphost=".$_SERVER['HTTP_HOST'];
    265     //echo $url;
    266     $r=file_get_contents($url);
    267     }
    268    
    269     //echo "<h2>Score: $score</h2";
    270    
    271 }
    272 
    273 
    274 
     292   
     293   
     294   
     295   
     296}
     297
     298
     299
     300function shsb_cron_run()
     301{
     302   
     303    $shsb_score_time=get_option( "shsb_score_time",0);
     304    if ($shsb_score_time==0 || time()-$shsb_score_time>60*60*11)
     305    {
     306    $score=shsb_calculate_score();
     307
     308    add_option( 'shsb_score', $score, '', 'no' );
     309    add_option( 'shsb_score_time', time(), '', 'no' );
     310    }
     311   
     312}
     313
     314function shsb_activate() {
     315
     316    // Activation code here...
     317         
     318    if( !wp_next_scheduled( 'shsb_cron' ) )
     319    {
     320    wp_schedule_event( time(), 'hourly', 'shsb_cron' );
     321    }
     322
     323}
     324
     325add_action ('shsb_cron',  'shsb_cron_run' );
     326
     327function shsb_deactivate()
     328{
     329
     330wp_clear_scheduled_hook('shsb_cron');
     331
     332}
     333
     334register_activation_hook( __FILE__, 'shsb_activate' );
     335
     336
     337
     338register_deactivation_hook( __FILE__, 'shsb_deactivate' );
     339
     340
     341 
    275342?>
Note: See TracChangeset for help on using the changeset viewer.