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');