Source: medium.com

Laravel Api Polling System

Category: Laravel, api

Sometimes, when server is performing huge tasks, after we send a http request, it takes a huge time to load response.

Polling is a way, in which the process is assigned a unique id, and an api keeps checking for the process to complete using that unique id.

But the problem with using middlewares is I’ve to pass $next to dispatch() funciton and since next is of type Clouse and Closures can’t be serialized, I couldn’t use this technique.

To poll any api, we have to wrap the processing in a Job class, and we have to pass the job and processing to ProcessApiPoll::addToPoll(JobClass::class, $param1, $param2 …

And it will save the json_encoded form of response to the ApiPoll database we have created before, which will be accessed through the api we are going to create.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners