Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kawashita's avatar

Right method to request a queue API

Ok so this might seems easy for some and complicated for others, I belong to the group who think it is complicated So if someone please can give me a solution

I am going to deal with an API, I am the client, I will do a request get a Json response of a list of info and format this Json object into an excel file then save it in some folder with a proper logic.

I could do all this but here is the tricky part:

the API is a Queue, for each time I request it a new object is sent in a response, once I get that response, the object disappears from the queue and lead to the next one until the queue gets empty and I would receive an empty body or some flag telling me "0 remaining".

How would I be able to continue to perform requests and stop right at when the queue is empty then get back to it when there is a new object waiting to be read?

0 likes
7 replies
fylzero's avatar

@kawashita Sounds like you need to look into Guzzle. You can use this to call the API from PHP and hand the response directly to the code creating the Excel file.

kawashita's avatar

Thank you Flyzero for the answer Well i know about this. What i am still not sure how to perform is the queue? I hope you understood my question

fylzero's avatar

@kawashita I'm not sure I understand the architecture of what you are going for.

Either you mean that you pull a request front he API, where you can order by I'd and delete the entries as you pull them from the Api... which sounds pretty straight forward...

Or you mean you pull from the API and queue a job based on what you pull. Also straight forward.

Say more?

kawashita's avatar

Neither of them, the api has one object at a time once i request it is sent in the response then deleated simultanously from the system database. Now when i request again the api i get another object. I dont know how many times i should continie to request since each time it's a different object inside a queue. I do know that i should stop requesting once the object is empty but how to trigger back again the requests when there more objects in this queue

willvincent's avatar
Level 54

This sounds like a strange scenario.. but I think the way to approach this is to have a cron task that runs every minute, every 5 minutes, whatever frequency.. and it should first check if queue items are being processed by looking at a flag set in the DB or similar. If no items are being processed, initiate your api call to fetch an item from the queue -- this is where you'll set that items are being processed.. After receiving an item and processing it, hit the api again.. repeat until you get your empty state, at which point you then toggle the processing flag off again. Next time the cron job runs it'll see processing is not occurring, flip the flag, check the api, and either process items or toggle the flag back off.

kawashita's avatar

Thanks will I guess i need to check everytime with a certain frequency. Nice clearification about the flag too

Please or to participate in this conversation.