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

KodaC's avatar
Level 1

Continuous API query - How to implement?

The API is very special and I will try to explain it with a simple example.

Each user can enter several personal tokens into the database. For each of these tokens, I would like to call an API every 15 minutes (later perhaps more often) and store the response in a database.

The API is a Rest API that I could query with e.g. Guzzle.

Since I haven't been working with Laravel for very long, I don't know how I can best implement this. It would be good if I could move this to a second server later on to reduce the load on the actual homepage.

I have tried to read up on the documentation of queues, jobs, broadcasting and task scheduling, but I am still unsure what I could implement this with.

0 likes
4 replies
Tray2's avatar

You should use a job queue for that

KodaC's avatar
Level 1

Thank you very much for all the answers and the hint with the http client.

One of the examples I found was with task schedules and commands. I think the way @sinnbeck means it?

Have I now understood this correctly?

  • I create a scheduled task with a command. This runs in the background as it can take longer
$schedule->command(CallMyAPICommand::class)->everyFifteenMinutes()->runInBackground();
  • (Later I could roll out my Laravel installation on a second server and only set up the cronjob there to reduce the load)
  • In my CallMyAPICommand, I would then retrieve all tokens and execute the API in a loop each time?
$tokens = Token::wherseDate('last_api_call', '>=', Carbon::now()->addMinutes(15));
foreach ($tokens as $token) {
	//Make Request
}

I used to have my old API class in a small composer package with Guzzle. Since I don't need Guzzle anymore and want to use Http client from Laravel, could I just create the API class e.g. in "app/APIs/Api_Name/Api_NameClient.php", or does Laravel provide a directory for it, or should I continue to solve it with a composer package which requires Laravel instead of Guzzle?

Please or to participate in this conversation.