diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index f4d3cbc..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,4 +0,0 @@ -preset: laravel - -disabled: - - single_class_element_per_statement diff --git a/README.md b/README.md index 8653eb5..86a7362 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ class Kernel extends HttpKernel ]; ``` +--- + By default, the middleware measures only three things, to keep it as light-weight as possible: - Bootstrap (time before the middleware gets called) @@ -49,7 +51,7 @@ By default, the middleware measures only three things, to keep it as light-weigh Once the package is successfully installed, you can see your timing information in the developer tools of your browser. Here's an example from Chrome: -![image](https://user-images.githubusercontent.com/40676515/73973252-d831a980-48e7-11ea-88fc-a606fd5b758a.png) +![CleanShot 2024-03-18 at 13 48 53@2x](https://github.com/beyondcode/laravel-server-timing/assets/26432041/adea40e4-5c34-4aee-9fb7-ad6bac40addc) ## Adding additional measurements @@ -66,6 +68,9 @@ sleep(5); ServerTiming::stop('Running expensive task'); ``` +![CleanShot 2024-03-18 at 13 51 56@2x](https://github.com/beyondcode/laravel-server-timing/assets/26432041/47e9e692-2bce-4449-a7ea-966fa4701cdb) + + If you already know the exact time that you want to set as the measured time, you can use the `setDuration` method. The duration should be set as milliseconds: ```php @@ -85,16 +90,16 @@ ServerTiming::setDuration('Running expensive task', function() { You can also use the Server-Timing middleware to only set textual information without providing a duration. +```php +ServerTiming::addMetric('User: '.$user->id); +``` + ## Publishing configuration file The configuration file could be published using: `php artisan vendor:publish --tag=server-timing-config` -You can disable the middleware changing the `timing.enabled` configuration to false. - -```php -ServerTiming::addMetric('User: '.$user->id); -``` +You can disable the middleware by changing the `timing.enabled` configuration to false or adding `SERVER_TIMING_ENABLED=false` to your `.env` file. ### Testing diff --git a/composer.json b/composer.json index 907ea8d..9ed445b 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ ], "require": { "php": "^7.2|^8.0", - "illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", "symfony/stopwatch": "^4.0|^5.0|^6.0|^7.0" }, "require-dev": { - "orchestra/testbench": "^4.6|^5.0|^6.0|^8.0", - "phpunit/phpunit": "^8.0|^9.0" + "orchestra/testbench": "^4.6|^5.0|^6.0|^8.0|^10.0", + "phpunit/phpunit": "^8.0|^9.0|^11.5.3" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1eef57c..5119f0b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,7 @@ @@ -14,16 +9,4 @@ tests - - - src/ - - - - - - - - - diff --git a/src/Facades/ServerTiming.php b/src/Facades/ServerTiming.php index 4aeb380..a6f2081 100644 --- a/src/Facades/ServerTiming.php +++ b/src/Facades/ServerTiming.php @@ -4,8 +4,26 @@ use Illuminate\Support\Facades\Facade; +/** + * @method static \BeyondCode\ServerTiming\ServerTiming start(string $key) Start a unique timed event. + * @method static \BeyondCode\ServerTiming\ServerTiming addMetric(string $metric) Add new event with null duration. + * @method static bool hasStartedEvent(string $key) Check if a event has been created already. + * @method static \BeyondCode\ServerTiming\ServerTiming measure(string $key) Stop existing event and record its duration, else start a new event. + * @method static \BeyondCode\ServerTiming\ServerTiming stop(string $key) Stop a timed event and record its duration. + * @method static void stopAllUnfinishedEvents() Stop all running events. + * @method static \BeyondCode\ServerTiming\ServerTiming setDuration(string $key, float|int|callable $duration) Set the duration for an event if $duration is number, else record elapsed time to run a user function if $duration is callable. + * @method static float|int|null getDuration(string $key) Retrieve the duration an event has taken. + * @method static array events() Get the list of finished events with their associated duration. + * + * @see \BeyondCode\ServerTiming\ServerTiming + */ class ServerTiming extends Facade { + /** + * Get the registered name of the component. + * + * @return string + */ protected static function getFacadeAccessor() { return \BeyondCode\ServerTiming\ServerTiming::class; diff --git a/src/config/config.php b/src/config/config.php index 07708db..65ce80e 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -11,5 +11,5 @@ | */ - 'enabled' => true, + 'enabled' => env('SERVER_TIMING_ENABLED', true), ];