1. Go to this page and download the library: Download smnandre/pagespeed-api 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/ */
smnandre / pagespeed-api example snippets
use PageSpeed\Api\PageSpeedApi;
$pageSpeedApi = new PageSpeedApi();
// or with API key (optional)
$pageSpeedApi = new PageSpeedApi('YOUR_API_KEY');
// Analyze a page
$analysis = $pageSpeedApi->analyse('https://example.com/');
// ...with a specific strategy (mobile or desktop)
$analysis = $pageSpeedApi->analyse('https://example.com/', 'mobile');
// ...with a specific locale (e.g., fr_FR)
$analysis = $pageSpeedApi->analyse('https://example.com/', locale: 'fr_FR');
// ...with a specific category (performance, accessibility, best-practices, seo)
$analysis = $pageSpeedApi->analyse('https://example.com/', categories: 'performance');
use PageSpeed\Api\PageSpeedApi;
$pageSpeedApi = new PageSpeedApi();
$report = $pageSpeedApi->analyse('https://www.example.com')->report();
// Scores (null when the category was not analysed)
$report->performance->value; // 88
$report->performance->rating; // Rating::NeedsImprovement
$report->performance->rating->value; // 'needs-improvement'
$report->seo->value; // 90
// Core Web Vitals (null when field data is unavailable)
$report->lcp->value; // 2300
$report->lcp->unit; // 'ms'
$report->lcp->rating; // Bucket::Fast
// Serialise for a template, a CLI or an API
$report->toArray();
json_encode($report);