What is WebPagetest?
Webpagetest is one of the most popular and free tools for measuring webpage performance. Webpagetest enables you to run web performance tests on your site from a number of different locations across the world in a number of different browsers.
Enter your website and click Start Test. Next, you will see the output window like below
From this page, you can find values for following parameters of your webpage
- Load Time – Time requires to load the page
- First Byte Time – Time when your request started to execute
- Page Size – Total Size for your Web page
- Requests – Number of Requests your Webpage made.
Webpagetest has 2 primary API
- To Run Tests – http://www.webpagetest.org/runtest.php.
- To Check Test Status - http://www.webpagetest.org/testStatus.php
- To get Test Results - http://www.webpagetest.org/testStatus.php
To Run Tests:
What is JVM (Java Virtual Machine) with Architecture JAVA Programming Tutorial
- To run a test you can make a GET or a POST to http://www.webpagetest.org/runtest.php.
- In response, you will either get re-directed to the results page or you will receive an XML response (depending on if XML was requested).
- You need API KEY to use Webpagetest API, and you have to contact wepagetest.org to get your API KEY. With this API key, you can submit max 100 tests per day for more you need a private instance. For Private instance - set up a test environment on your own server.
- Sample - http://www.webpagetest.org/runtest.php?url=guru99.com&runs=1&f=xml&k=
- URL – URL to be tested
- runs – Number of test runs
- fvonly – Set to 1 to skip the Repeat View test
- f – Response Format. Set to XML to Request an XML response or JSON for JSON encoded response
- k - API Key (required for public instance)
To Check Test Status
- Once you submit a test, you will get the following XML response.
- Check testId field in response and note it
- Webpagetest is a free and popular tool so to ensure fair usage, your Request has to stand in the queue and wait for your turn.
- You can check test status by doing a GET to http://www.webpagetest.org/testStatus.php with your test id.
- Example - http://www.webpagetest.org/testStatus.php?f=xml&test=141107_12_BXZ
This information gives the test ID, the start time, the number of runs the test requested, etc.
To Check Test Results
Pass the tested to the API - http://www.webpagetest.org/xmlResult/141107_12_BXZ/
You will see the Test results in XML format like below
Php Code sample to use Webpagetest API<?php $url = <a href=http://guru99.com //url to test $api_key = ""; // your api key $webpagetest = "http://www.webpagetest.org/runtest.php?url=$url&runs=1&f=xml&k=$api_key"; $xmlres = simplexml_load_file($webpagetest); $testid = $xmlres->data->testId; echo "Test id : ".$testid." For url : ".$url; ?>
- Now Make another call after some time to get test results