I have a PHP script which sends a message to a number of users, with 6 mins delay in between. SO if there is 30 users, the script should run for 3 hours, to complete sending message to all 30 users. I tried Background Jobs with Workers in PHP, but the script stops after 30 minutes. Is there any way to increase the timeout, or is there any other way to achieve this?
Asked
Active
Viewed 182 times
-2
-
use cron jobs. Here is how to: https://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php – Cemal Apr 09 '18 at 10:00
-
but i have to get the list of users id. And then send message to each on of them , how can i implement that using cron. – Jerin A Mathews Apr 09 '18 at 10:05
-
1save your last sent user's personna in somewhere (file, db etc.) when your cron works, read it from there and step onto next one. This way, you'll use way less resources – Cemal Apr 09 '18 at 10:09
-
Do u know how to start a cron job in heroku? – Jerin A Mathews Apr 09 '18 at 10:52
-
you can use either [scheduler](https://devcenter.heroku.com/articles/scheduler) or [custom clock process](https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes) or you can check https://stackoverflow.com/questions/2611914/running-cron-tasks-on-heroku – Cemal Apr 09 '18 at 12:33
-
i already tried this, The custom clock process only available to python nd java. then this daily scheduler has only min 10mins interval. – Jerin A Mathews Apr 09 '18 at 12:58
-
there's also the 3rd option. – Cemal Apr 09 '18 at 12:59
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168571/discussion-between-jerin-a-mathews-and-cemal). – Jerin A Mathews Apr 09 '18 at 14:39
2 Answers
0
So at last what I did is, I start a cron job which calls this script every 5 mins. In the script, I check a file whether it contains any message, if there is, I will send it to users if not ignore.
So when I set up the message to sent to users, I will save the message and list of users in different files. After sending the message to each user, I delete them from the list. As soon as the users list become empty, I delete the message from the file too. In this way, the script will know, that it sends the message to all the users. By far it's working well. I am using cron-job.org
for creating cron job. It's free in there.

Jerin A Mathews
- 8,572
- 4
- 26
- 49