-4

How can I allow a PHP script to run once per day even if it is launched multiple times?

  • 3
    Possible duplicate of [How can I run PHP script in certain interval (e.g. once a day)?](http://stackoverflow.com/questions/865381/how-can-i-run-php-script-in-certain-interval-e-g-once-a-day) – Script47 Aug 20 '16 at 18:41
  • 1
    All you had to do was [Google](https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=How+Can+I+Make+A+PHP+Script+Only+Run+Once+Per+Day) your title. Please put some effort in in researching before asking questions. – Script47 Aug 20 '16 at 18:41
  • 1
    Use cron jobs :), welcome to SO :) – Derick Alangi Aug 20 '16 at 18:41
  • By using Cron jobs – kikuyu1 Aug 20 '16 at 18:44
  • 1
    **[Cronless](http://stackoverflow.com/questions/26154395/how-to-execute-a-block-of-code-in-php-once-per-day-in-main-template-file-non-cr)** - By the way, it was the first result of Googling your title. – Script47 Aug 20 '16 at 18:47
  • The comments here are a bit harsh. I think the point was that it should only run once a day even if lauched serveral times a day. Just saying 'use cron' doesn't answer that question fully. Something like: "Make sure your cron job only runs once a day, and don't put the script on a public server.", could have been added. – KIKO Software Aug 20 '16 at 19:12
  • Thanks, @KIKOSoftware. However, how would I "Make sure your cron job only runs once a day." – Nathan Quackenboss Aug 26 '16 at 18:12
  • @Nathan: Two ways: 1. Do not put it in a public webserver directory so other people can run it. 2. Register the time it runs somewhere, and check that value when running it again at the beginning of the PHP script. – KIKO Software Aug 26 '16 at 18:28
  • @KIKOSoftware That seems like it would work. But I don't know PHP that well, so could you give me the code to do that? – Nathan Quackenboss Aug 27 '16 at 10:30
  • @Nathan. I'm sorry, storing a value and retrieving it, and comparing date/times, are very basic operations. You can find examples everywhere. Here on Stack Overflow it is always appreciated if you, at least, show some effort to find a solution yourself. If you cannot make it work, ask a new question and show what you've tried. – KIKO Software Aug 27 '16 at 17:33

1 Answers1

0

on a linux server use cron , you will be able to choose what frequency it will be run : https://help.ubuntu.com/community/CronHowto

on a windows server :

What is the Windows version of cron?

after your edit : see @script47's comment

By the way, cron is very simple to use, dont be affraid of it

Community
  • 1
  • 1
singe batteur
  • 407
  • 2
  • 13