Help in implementing Task Scheduler in PHP

I have a table, that consists of all the info to run a campaign. The info includes, the time interval to check the campaign (10 mins, 15 mins etc.) and other information to check whether it meets the specific requirement or not, to run the campaign.

At the moment, what I am planning to do is:

  • Add my code in one php file
  • In the code, go through all the rows of the table
  • Check if it’s the time to check the campaign or not (via the interval)
  • If it’s the time to check the campaign, then go through other details of the table and based on the set conditions, send an email or SMS.
  • I am planning to run a cron job which goes through this php file, after every 10 minutes (As it’s the shortest check interval)

I need suggestions, whether it’s the proper solution or not OR if someone has any better and efficient solution?

I would reduce the interval to every 5 minutes, but that sounds like the way to go about it in PHP. In Python there are more options, and in PHP you could go with Laravel’s task scheduler, but for ease of implementation, I would do what you are planning if it were my project.

Do you see any problems in it? Example: Should I use message queues or something else you would recommend?

So I recently built something simliar for a notification system that sends SMS and emails based on a customers notification preferences for new/ used products a store offers.

You don’t want to do this. What you want to do is only get back the rows that are within the criteria that should be run. Doing otherwise will really hamper the database and tax the server.

Whether you need a queue or not depends on the current load and the expected load. It’s the difference between going through 100 records, vs 10,000 an hour. And if you have that much of a load, then I would say PHP is not the best language to use for the processing of those requests.

Overall, it sounds good, but I am only going on limited information. What does “check the campaign” actually mean?

@astonecipher
Check the campaign means, I have set intervals with each campaign, that is, when it actually needs to be checked (10 mins, 15 mins, 20 mins, 25 mins etc.) So, logically, I won’t be extracting all the data. I will put a ‘WHERE’ clause, based on this. Moreover, I won’t be having that much data.

That sounds like the best idea so far.

What does checking a campaign entail though? Is there another type of hook you could use other than a cron job?

Basically, when a campaign is created, the interval is chosen from drop down menu and stored in the table. So, I will check that if according to the present time, campaign needs to be checked or not and Email/SMS has to be sent or not.

Okay, then how you are doing this is how I did my notification system.

Yes, most probably. So, your notification system is plain php and working fine?

A few class files and a driver file that the cron executes. Makes calls to Mailgun for email notifications and Twilio for MMS’s.

1 Like

Thank you so much for all your responses.

Sponsor our Newsletter | Privacy Policy | Terms of Service