Changeset 2077511
- Timestamp:
- 04/30/2019 04:30:12 AM (7 years ago)
- Location:
- super-host-speed-benchmark/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
shsb.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
super-host-speed-benchmark/trunk/readme.txt
r2076811 r2077511 43 43 0.3 Fixed SQL error in benchmark 44 44 45 0.4 Added caching machanism for score using wpcron 46 -
super-host-speed-benchmark/trunk/shsb.php
r2076811 r2077511 4 4 * Plugin URI: https://superhostspeed.com/ 5 5 * 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. 36 * Version: 0.4 7 7 * License: GPL2+ 8 8 * Copyright 2019 Anthony Walker … … 17 17 add_action( 'admin_menu', 'shsb_add_admin_menu' ); 18 18 add_action( 'admin_init', 'shsb_settings_init' ); 19 20 19 21 20 22 … … 127 129 add_action('admin_menu', 'shsb_add_pages'); 128 130 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 131 function shsb_calculate_score() 132 { 138 133 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(); 143 135 144 136 $table_name=$wpdb->prefix ."speedtest202"; … … 191 183 192 184 $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 195 return $score; 196 197 } 198 199 // action function for above hook 200 function 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 206 function 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 } 193 225 194 226 $purl= plugins_url(); … … 258 290 EOT; 259 291 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 300 function 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 314 function 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 325 add_action ('shsb_cron', 'shsb_cron_run' ); 326 327 function shsb_deactivate() 328 { 329 330 wp_clear_scheduled_hook('shsb_cron'); 331 332 } 333 334 register_activation_hook( __FILE__, 'shsb_activate' ); 335 336 337 338 register_deactivation_hook( __FILE__, 'shsb_deactivate' ); 339 340 341 275 342 ?>
Note: See TracChangeset
for help on using the changeset viewer.