Hi,
Is there a way to load "as less Laravel as possible" when processing a webhook? The objective here is to send the response asap otherwise the external system would send the same webhook again and eventually would disable webhooks at all.
Note: I'm using queued jobs already, so my controller looks like this:
class WebhooksController extends Controller
{
public function process(Request $request)
{
if ($request->has('leads.update')) {
// do not process this kind of hooks…
return response("Ok", 200);
}
try {
// Cache-related routines:
$job = new \App\Jobs\UpdateLeadJob($request->all());
$this->dispatch($job);
} catch (\Exception $e) {
Log::critical("[webhooks] dispatching primary job failed: {$e->getMessage()}", $request->all());
}
try {
// Custom webhook processors:
$customJob = $this->getCustomJob($request);
if ($customJob) {
$this->dispatch($customJob);
}
} catch (\Exception $e) {
Log::critical("[webhooks] dispatching custom job failed: {$e->getMessage()}", $request->all());
}
$executionTime = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
if (1.9 < $executionTime) {
Log::error("[webhooks] webhook processing took more than 2 secs!", $request->all());
}
return response("Ok", 200);
}
// ...
}
Still, it happens sometimes that it's not fast enough. So, I can usually see several "webhook processing took more than 2 sec" messages in the logs.
So, probably I need a way to disable middlewares or something else… Is there any way to reduce the application loading time for this single action?
Note: I'll still need means to analyse request (like that if ($request->has(..))) and to dispatch queued jobs.