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

Mfrancik's avatar

Queue logic

I have an application thats purpose is to send many text messages in a short period of time. I run into limitations because I can only send 1 text message per second per phone number. There are times the user may want to send 1000 text messages with 5 different phone numbers (but sometimes 500 with one number, 200 with another, etc..). Now I want to concurrently send text messages if the phone numbers are unique.

I could setup seperate queues per phone number, but that will be a nightmare, and expensive.

Using mysql as a queue is an easy solution, and run a cron that groups by phone number and sends every second, but i KNOW this is bad practice and every mysql performance site says dont do this.

maybe a silly question, but if i setup a second database on my server with just one table acting as a queue, will this slow mysql down as a whole on the server?

0 likes
2 replies
fideloper's avatar

I think the solution I would try is:

  1. Use multiple queue workers (to get concurrent jobs running).
    • This can be scaled out on multiple servers, with more queue workers running, as needed
  2. Have each job take care a phone number. So each job will take one phone number and send each text message for that phone number (maybe with a call of sleep(1); between each SMS send)

Adding a 2nd second won't really help. Rather than being an issue of database performance (it might be, but likely isn't), it's mostly an issue of how databases work with transactions and timing.

Note: You'll very likely accidentally run a job more than once when you use multiple workers against the database driver for queue workers. I'd investigate using another queue worker type. Forge comes with Beanstalk on the server, that might be a good place to start.

I generally use AWS's SQS as it's very cheap and is one less piece of software to manage. However, it has it's own caveats that you may run into in terms of job run-time - you'll want to increase the default SQS queue's Visibility Timeout (or change it per-job to be something high).

The method I described above would have less queue jobs (one job per phone number) but take more time per job ( # SMSes to send * (1 second + api call time) ). Just be sure not to set a total job time allowed (don't set a --timeout flag on queue workers).

Snapey's avatar

How are you sending the SMS? I would have expected you to use a bureau for this, and they will take care of queuing in their own infrastructure.

Please or to participate in this conversation.