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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners