GithubHelp home page GithubHelp logo

laravel-vapor-support's Introduction

Laravel Vapor Support

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A small support package to help large Vapor applications which may occasionally hit "Internal Server Error" due to large request sizes.

This package provides a middleware to monitor the main response:

  • Illuminate\Http\Response
  • Illuminate\Http\JsonResponse
  • Symfony\Component\HttpFoundation\BinaryFileResponse

There is also support for:

  • Symfony\Component\HttpFoundation\StreamedResponse

However, because a streamed response length is generally unknown, by default a 'info' level log is recorded to aid debugging.

This package provides a middleware which can be used to monitor the length of the response body. This allows you to be notified if a page is starting to exceed the Vapor/AWS limits. The default logs included allow for route name (if set), url and size to be logged to help you pinpoint any pages of concern.

Installation

You can install the package via composer:

composer require richardstyles/laravel-vapor-support

You can publish the config file with:

php artisan vendor:publish --tag="laravel-vapor-support-config"

This is the contents of the published config file:

return [
    'warning_size' => env('VAPOR_SUPPORT_RESPONSE_WARNING_SIZE', 5000000),
    'warning_action' => \RichardStyles\LaravelVaporSupport\Actions\ResponseSizeWarning::class,


    'limit_size' => env('VAPOR_SUPPORT_RESPONSE_LIMIT_SIZE', 6000000),
    'limit_action' => \RichardStyles\LaravelVaporSupport\Actions\ResponseSizeLimit::class,

    'stream_action' => \RichardStyles\LaravelVaporSupport\Actions\StreamResponseMonitor::class,
];

Usage

Simply add the middleware to either the Kernal.

app/Http/Kernel.php

protected $middlewareGroups = [
        'web' => [
             ...
            \RichardStyles\LaravelVaporSupport\Http\Middleware\ResponseLimitMonitor::class,
        ],
        ...

Or as a named middleware to use on individual routes.

protected $routeMiddleware = [
        ...
        'response.monitor' => \RichardStyles\LaravelVaporSupport\Http\Middleware\ResponseLimitMonitor::class,
    ];

For monitoring response sizes (in bytes), these can be set in your .ENV, or by modifying the config.

Examples set very low

VAPOR_SUPPORT_RESPONSE_WARNING_SIZE=1000
VAPOR_SUPPORT_RESPONSE_LIMIT_SIZE=5000

Using the example above would cause;

  • The Warning class run when response body exceeds "1000" bytes.
  • The Limit class runs when response body exceeds "5000" bytes.

The config also allows the base classes to be overridden. The Limit and Warning classes must implement RichardStyles\LaravelVaporSupport\Contracts\HandlesResponsesLimit The stream response should implement RichardStyles\LaravelVaporSupport\Contracts\HandlesStreamResponse as with streamed responses you cannot easily know it's length.

The default actions taken by this package is to Log either:

  • Log info on streamed response
  • Log warning when request length exceeds warning_size
  • Log critical when request length exceeds limit_size

By implementing your own classes and setting these within the config vapor-support you can notify/alert however your application requires, such as to Bugsnag or other third party services.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Support

If you are having general issues with this package, feel free to contact me on Twitter.

If you believe you have found an issue, please report it using the GitHub issue tracker, or better yet, fork the repository and submit a pull request with a failing test.

If you're using this package, I'd love to hear your thoughts. Thanks!

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-vapor-support's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar richardstyles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.