PHP code example of rocketeers-app / lighthouse-php

1. Go to this page and download the library: Download rocketeers-app/lighthouse-php 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/ */

    

rocketeers-app / lighthouse-php example snippets


use Rocketeers\Lighthouse\Lighthouse;

(new Lighthouse())
    ->setOutput('report.json')
    ->accessibility()
    ->bestPractices()
    ->performance()
    ->pwa()
    ->seo()
    ->audit('http://example.com');

use Rocketeers\Lighthouse\Lighthouse;

(new Lighthouse())
    ->setOutput('example', ['html', 'json'])
    ->performance()
    ->audit('http://example.com');

use Rocketeers\Lighthouse\Lighthouse;

(new Lighthouse())
    ->withConfig('./my-config.js')
    ->audit('http://example.com');

use Rocketeers\Lighthouse\Lighthouse;

(new Lighthouse())
    ->setNodeBinary('/usr/bin/node')
    ->setLighthousePath('./node_modules/lighthouse/lighthouse-cli/index.js')
    ->audit('http://example.com');

use Rocketeers\Lighthouse\Lighthouse;

(new Lighthouse())
    // these are the default flags used
    ->setChromeFlags(['--headless', '--disable-gpu', '--no-sandbox'])
    ->audit('http://example.com');



use Rocketeers\Lighthouse\Exceptions\AuditFailedException;
use Rocketeers\Lighthouse\Lighthouse;


try {
(new Lighthouse())
    ->performance()
    ->audit('http://example.com');
} catch(AuditFailedException $e) {
    echo $e->getOutput();
}

composer