Best approach for external one-time-per-request log dump #1624
-
|
Hello Bref community, I am still in thinking mode about an idea. What I would like to complete for this idea, is to provide some information (throughout the PHP/Laravel request) to S3, as a single S3 API call, at the end of the request. Is there a way to easily do that, without using other services (eg: a database or a cookie) to: I would also like this to be resilient (e.g.: on failure perhaps queue the logging in SQS, again in a single message, for later... sending). Thanks so much for the brainstorming help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi! I'd write a class that stores information in memory, and then would send the data at the end of the request. In Laravel, you can execute code at the end of an HTTP request using a middleware and the php artisan make:middleware TerminateMiddlewareThis will generate a new middleware class named <?php
namespace App\Http\Middleware;
use Closure;
class TerminateMiddleware
{
public function handle($request, Closure $next)
{
return $next($request);
}
public function terminate($request, $response)
{
// Code to run at the end of the request
}
}Next, you need to register the middleware in the protected $middleware = [
// Other middleware entries
\App\Http\Middleware\TerminateMiddleware::class,
];Now, the |
Beta Was this translation helpful? Give feedback.
Hi! I'd write a class that stores information in memory, and then would send the data at the end of the request.
In Laravel, you can execute code at the end of an HTTP request using a middleware and the
terminatemethod. Create a middleware using the following Artisan command:This will generate a new middleware class named
TerminateMiddlewarein theapp/Http/Middlewaredirectory. Open the file and modify it: