spatie/lighthouse-php
Run Google Lighthouse audits from PHP. Test any URL and retrieve category scores (performance, accessibility, SEO, etc.) and individual audit details. Configure headers, user agent, categories, CPU throttling, and max load wait, then run and parse results.
With the package installed, this is how you can get run lighthouse.
use Spatie\Lighthouse\Lighthouse;
// returns an instance of Spatie\Lighthouse\LighthouseResult
$result = Lighthouse::url('https://example.com')->run();
You can use the scores method to get scores of the five categories Lighthouse runs audits for.
$result->scores(); // returns an array like this one:
/*
* [
* 'performance' => 98,
* 'accessibility' => 83,
* 'best-practices' => 90,
* 'seo' => 92,
* 'pwa' => 43,
* ]
*/
Here's how you can get the results of an audit:
$result->audit('first-contentful-paint');
/* returns this array
*
* [
* 'id' => 'first-contentful-paint'
* 'title' => 'First Contentful Paint'
* 'score' => 0.98
* 'scoreDisplayMode' => 'numeric'
* 'numericValue' => 1262.95
* 'numericUnit' => 'millisecond'
* 'displayValue' => '1.3 s'
* ]
*/
To get the results of all audits, call audits().
// returns an array with the results of all audits
$result->audits();
How can I help you explore Laravel packages today?