1. Go to this page and download the library: Download widgetsburritos/webpagetest library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
widgetsburritos / webpagetest example snippets
use WidgetsBurritos\WebPageTest\WebPageTest;
$wpt = new WebPageTest('YOUR_API_KEY');
if ($response = $wpt->runTest('https://www.google.com')) {
if ($response->statusCode == StatusCode::OK) {
// All test info is available in $response->data.
$test_id = $response->data->testId;
}
}
$options = [
'label' => 'My Test Label',
'noimages' => 1,
'mobile' => 1,
];
if ($response = $wpt->runTest('https://www.google.com', $options)) {
if ($response->statusCode == StatusCode::OK) {
// All test info is available in $response->data.
$test_id = $response->data->testId;
}
}
if ($response = $wpt->getTestStatus($test_id)) {
// All test info is available in $response->data.
if ($response->statusCode == StatusCode::OK) {
// Test is complete.
}
else if ($response->statusCode == StatusCode::CONTINUING) {
// Test is running.
}
else if ($response->startCode == StatusCode::SWITCHING_PROTOCOLS) {
// Test is waiting to start.
}
else if ($response->statusCode == StatusCode::PAYMENT_REQUIRED) {
// Test has been cancelled.
else {
// Test failed.
}
}
if ($response = $wpt->getTestResults($test_id)) {
// All test result info is available in $response->data.
if ($response->statusCode == StatusCode::OK) {
// Test is complete.
}
else if (in_array($response->statusCode, [StatusCode::CONTINUING, StatusCode::SWITCHING_PROTOCOLS])) {
// Test is not yet complete.
}
else {
// Test failed.
}
}
if ($response = $wpt->getLocations()) {
if ($response->statusCode == StatusCode::OK) {
// All locations info is available in $response->data.
}
}
$wpt->cancelTest($test_id);
use WidgetsBurritos\WebPageTest\WebPageTest;
$wpt = new WebPageTest('YOUR_API_KEY', $handler);
use WidgetsBurritos\WebPageTest\WebPageTest;
$wpt = new WebPageTest('YOUR_API_KEY', $handler, 'https://www.example.com');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.