views:

56

answers:

2

I'm using a third-party API to send messages to users. But this third-party limits 30 calls per hour. I'm using PHP on linux. What's the best way to implement this?

A: 

You can make use of a database for this.

You can create one table to keep track of number of messages sent by you in the current hour. check the table before sending the message to ensure that you've not exceeded the hourly limit. If not exceeded send the message, else you en queue the message by inserting it in a table so that it can be sent in the next hour. To allow a FIFO behavior you could give an auto increment id or a time stamp for each inserted message.

codaddict
A: 

I'd probably start by setting up the message queue as a table in a database. Then you'll write a PHP script that will read from the database table and send up to 30 queue'd messages at a time. Schedule that PHP script as a cron job to run once every hour and you're all set.

Greg W