Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Created June 12, 2021 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshwaghmare/7334adc7f64cfbd18b78884f675d574a to your computer and use it in GitHub Desktop.
Save maheshwaghmare/7334adc7f64cfbd18b78884f675d574a to your computer and use it in GitHub Desktop.
webpagetest.org API example

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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment