How to run the PHP script at scheduled time

后端 未结 4 888
梦谈多话
梦谈多话 2020-11-30 15:17

I need to run a php script at the scheduled time daily to update some fields in database and to send automated email. How I can do this?

Is it possible to write so

4条回答
  •  自闭症患者
    2020-11-30 15:56

    Just create the script that does the required job, test it by hitting the URL in your browser once you are sure it works right. Copy the URL and add a Cronjob

    Then schedule this command to run at whatever time you want to run

    php ABSOLUTE_URL_TO_SCRIPT >> logfile
    

    The log file is optional. But it will give you a chance to see what happened.

    For example if you want to run your script every 4 hours, and assuming your script is at http://localhost/work/scripty.php and assuming that your http root is /var/www,

    you would run "crontab -e" in terminal and add the following line:

    * */4 * * * php /var/www/work/scripty.php
    

    If you need more information just comment I will update the answer.

提交回复
热议问题