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

iqlas's avatar
Level 4

Run Laravel queue with specified delay between each job

On Laravel (8) App, i have to send Http post requests to an external API that throttles to 1 request per 2 seconds and we have usually send the requests in batches of hundreds.

So is there a way i can send one request per 3 seconds (using job delay perhaps?)

Thanks.

0 likes
2 replies
iqlas's avatar
Level 4

I believe rate limit "blocks" the next job after the limit has been reached. What I am trying to implement is where every job executes and has a delay of fixed seconds before the next job kicks in. I have done this and it seems to work:

$start = Carbon::now();
$employees = StagedEmployees::all();
foreach ($employees as $emp) {
    $job = new PostEmployeeToMinistryOfLabor($emp);
    $job->delay($start->addSeconds(3));
    dispatch($job);
}

[The fact that the changes on Carbon instance ( addSeconds() ) is mutable kinda helps.] So the jobs get scheduled with delay but it only works well if the queue is working currently and it ignores the time taken by the job to finish. I am wondering if there is a recommended way to achieve this.

Please or to participate in this conversation.