2

I want to check the stock level every day at a certain time (say 11pm GMT) and email a list of items that are low on stock to the admin. I have managed to get the mailing function working but I am struggling to limit the checks to once a day (right now it sends an email to the admin email every time the page loads)

Your help will be much appreciated!

Rumesh
  • 329
  • 4
  • 12
  • 3
    You will need to put your script in a separate file and run once per day with a cron job – Fabio Mar 09 '14 at 19:36
  • What technology stack are you using? If LAMP as @Fabio mentions Cron will be your solution – JohnnyFaldo Mar 09 '14 at 19:37
  • what fabio said would be the best way to go you wont have to load any page and the cron job will be executed in a set interval but you will have to ask your server admin to do that – Ekusu Mar 09 '14 at 19:39
  • very few set ups require asking "server admin" to set up a cron job –  Mar 09 '14 at 19:40

2 Answers2

2

I think that you just need to put your script in a separate file and run once per day with a cron job

You might want to read more about cron jobs in this post How to create cron job using PHP?

Community
  • 1
  • 1
Fabio
  • 23,183
  • 12
  • 55
  • 64
  • I followed the instructions as provided in the link but I did not receive an email. It might be because the time zone of the server is not GMT. Still not sure if it worked 100% :( – Rumesh Mar 09 '14 at 21:21
  • Cron works with server time, so set the time for it according to server time, also check logs to see if you have any problems with the script. – Fabio Mar 09 '14 at 21:23
  • Its fine!! it's working!! I got the url wrong lol. Silly mistake. Thanks for your link :) – Rumesh Mar 09 '14 at 21:37
1

In case that impossible to run a cron job, you can save last mail time in DB or file and check timeout on page load.

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39