2017 © Pedro Peláez
 

library web-benchmark

Package for benchmarking web pages

image

sa/web-benchmark

Package for benchmarking web pages

  • Thursday, October 5, 2017
  • by AkimovSergei
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Web benchmark

Installation

composer require "sa/web-benchmark":"dev-master", (*1)

Configuration

Configuration file: Configs/app.php, (*2)


<?php return [ 'mail' => [ 'driver' => 'smtp', 'smtp' => [ // SMTP configs 'host' => 'smtp.mailtrap.io', 'port' => 2525, 'username' => '', 'password' => '', ], 'from' => [ // Sender 'email' => 'report@web.benchmark', 'name' => 'Web Benchmark', ], 'to' => [ // Send reports to 'email@example.com' ], ], 'sms' => [ 'api_key' => 'API_KEY_EXAMPLE', 'from' => 'Web Benchmark', ] ];

Usage

Creating instance, (*3)


use Sa\WebBenchmark\WebBenchmark; use Sa\WebBenchmark\Exceptions\InvalidArgumentException; $url = "https://www.google.com"; $competitors = [ "https://laravel.com", "https://symfony.com", "https://github.com", ]; try { $webBenchmark = new WebBenchmark($url, $competitors); } catch (InvalidArgumentException $e) {}

Create event manager, (*4)


use Sa\WebBenchmark\EventManager; use Sa\WebBenchmark\Listeners\NotifyViaEmailEventListener; use Sa\WebBenchmark\Listeners\NotifyViaSmsEventListener; $eventManager = new EventManager(); $eventManager->attach(NotFastestEvent::class, new NotifyViaEmailEventListener(['email@example.com'])); $eventManager->attach(TwoTimesSlowestEvent::class, new NotifyViaSmsEventListener(['123456789'])); $webBenchmark->setEventManager($eventManager);

Available event managers:, (*5)

  • NotifyViaEmailEventListener - Send email, if benchmarked website is loaded slower than at least one of the competitors
  • NotifyViaSmsEventListener - Send SMS, if benchmarked website is loaded twice as slow as at least one of the competitors

Run benchmark, (*6)


try { $webBenchmark->run(); } catch (\Exception $e) { }

Output data, (*7)


use Sa\WebBenchmark\Outputs\JsonOutput; $webBenchmark->setOutput(new JsonOutput); $json = $webBenchmark->output();

Available output:, (*8)

  • JsonOutput
  • HtmlOutput
  • ConsoleOutput
  • FileOutput
  • PlainTextOutput

Example, (*9)

Create index.php, (*10)


<?php require "../vendor/autoload.php"; use Sa\WebBenchmark\Outputs\ConsoleOutput; use Sa\WebBenchmark\WebBenchmark; /** * @param $resource * @param array $competitors */ function main($resource, array $competitors) { $webBenchmark = new WebBenchmark($resource, $competitors, new ConsoleOutput); $webBenchmark->run(); echo $webBenchmark->output(); } main("https://www.google.com", ["https://laravel.com", "https://github.com", "https://www.facebook.com"]);

$ php index.php, (*11)

The Versions

05/10 2017

dev-master

9999999-dev

Package for benchmarking web pages

  Sources   Download

MIT

The Requires