webpagetest.org API example

Advertisement

We can test our website speed on website https://webpagetest.org.

If you are developer and what to test your website though coding then checkout below Webpagetest API example.

We send the Webpagetest API rest request to test the site.

<?php
/**
 * Web Page Speed Test API
 *
 * URL: https://www.webpagetest.org/
 *
 * API Key: ----.-----.-----.----
 *
 * API URL: https://www.webpagetest.org/getLocations.php?f=html&k={API_KEY}
 *
 * => The following browser/location combinations are available:
 *
 * Dulles_IE9
 * Dulles_IE10
 * Dulles_IE11
 * Dulles:Chrome
 * Dulles:Canary
 * Dulles:Firefox
 * Dulles:Firefox Nightly
 * Dulles:Microsoft Edge
 * Dulles_MotoG:Moto G - Chrome
 * Dulles_MotoG:Moto G - Chrome Canary
 * Dulles_MotoG:Moto G - Chrome Beta
 * Dulles_MotoG:Moto G - Chrome Dev
 * Dulles_MotoG:Moto G - UC Browser
 * Dulles_MotoG:Moto G - UC Mini
 * Dulles_MotoG:Moto G - Opera Mini
 * Dulles_MotoG:Moto G - Firefox
 * Dulles_MotoG4:Moto G4 - Chrome
 * Dulles_MotoG4:Moto G4 - Chrome Canary
 * Dulles_MotoG4:Moto G4 - Chrome Beta
 * Dulles_MotoG4:Moto G4 - Chrome Dev
 * Dulles_MotoG4:Moto G4 - UC Browser
 * Dulles_MotoG4:MotoG4E - UC Mini
 * Dulles_MotoG4:Moto G4 - Opera Mini
 * Dulles_MotoG4:Moto G4 - Firefox
 * ec2-us-east-1:Chrome
 * ec2-us-east-1:IE 11
 * ec2-us-east-1:Firefox
 * ec2-us-west-1:Chrome
 * ec2-us-west-1:IE 11
 * ec2-us-west-1:Firefox
 * ec2-us-west-2:Chrome
 * ec2-us-west-2:IE 11
 * ec2-us-west-2:Firefox
 * ec2-eu-west-1:Chrome
 * ec2-eu-west-1:IE 11
 * ec2-eu-west-1:Firefox
 * ec2-eu-central-1:Chrome
 * ec2-eu-central-1:IE 11
 * ec2-eu-central-1:Firefox
 * ec2-ap-northeast-1:Chrome
 * ec2-ap-northeast-1:IE 11
 * ec2-ap-northeast-1:Firefox
 * ap-south-1
 * ec2-ap-southeast-1:Chrome
 * ec2-ap-southeast-1:IE 11
 * ec2-ap-southeast-1:Firefox
 * ec2-ap-southeast-2:Chrome
 * ec2-ap-southeast-2:IE 11
 * ec2-ap-southeast-2:Firefox
 * ec2-sa-east-1:Chrome
 * ec2-sa-east-1:IE 11
 * ec2-sa-east-1:Firefox
 */

$api_kay = 'xxx.xxxx.xxxx.xxx.xxxc';

$url = 'https://maheshwaghmare.com/';

/**
 * Process
 */
$request = 'http://www.webpagetest.org/runtest.php?url=' . $url .'&runs=1&f=json&k=' . $api_kay;

/**
 * Response
 */
$response = wp_remote_get( $request );

if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200) {
	
 	print_r( $response );

} else {

 	$body = wp_remote_retrieve_body( $response );
 	$body = json_decode( $body );
 	print_r( $body );

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.