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

Mfrancik's avatar

Too Many Concurrent HTTP Requests

I have a platform that sends a large amount of SMS. I may an API request and pass a callback URL which then notifies me of the outcome of the message. If i send 10k text messages over the span of 3 mins, i get bombarded with delivery responses.

Right now when a delivery response comes in, i throw the response in a queue and it gets handled. I believe what is happening is TOO MANY requests are coming in, and I cannot handle all of them.

any suggestions on handling this?

0 likes
8 replies
shez1983's avatar

what you need to do is when you make the api request - put that in the queue and even delay it by few seconds..

Snapey's avatar

are you genuinely queuing the callback or is your queue async?

You need to record it in the queue and respond to the callback asap so that you can deal with the next and then deal with the outcome in your own time.

Do you really need to send the messages so quickly? Another strategy might be to deliberately slow down sending.

Mfrancik's avatar

When the callback comes in, the request is genuinely put into a queue.

Right now, the request comes in, i convert the body of the request to json, then throw that content into a queue.

Unfortunately i do need send the messages this quickly.

I am quite unfamiliar with nginx. I was curious if this had settings for allowing concurrent http requests, and if too many come in, its blocking the ones coming in behind it.

Snapey's avatar

So you have a separate queue worker running to process the queue?

Your response to the callback should be really quick so there should be no problem keeping up?

Mfrancik's avatar

yeah, i have 5 workers working off that queue.

im using amazon SQS and it looks like the jobs are not all getting pushed to the queue. the handler im using for these requests hits one of my urls and throws the content straight into the queue.

Mfrancik's avatar

from a few more packet captures, it looks as if these jobs are being handled and hitting my server, but a large majority of them are not being added to queue when dispatched. Anybody else had issues with amazon SQS?

I am not exceeding the 300 per second limit.

Mfrancik's avatar
Mfrancik
OP
Best Answer
Level 3

since im using the api route, there is a thottle on the API middleware.

 protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \Laravel\Spark\Http\Middleware\CreateFreshApiToken::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

This throttle value was the issue.

1 like
Snapey's avatar

Glad to see you solved it. Thats a good one to know. Mark your own answer as correct.

1 like

Please or to participate in this conversation.