how to set cron job from php script?

后端 未结 3 945
Happy的楠姐
Happy的楠姐 2021-02-06 06:02

i am new to cron job . i studied some basics about cron job . i can able to call php using cron tab. By using following command in /etc/crontab

  10 *    * * *           


        
3条回答
  •  误落风尘
    2021-02-06 06:40

    From How can I set cron job through PHP script by Nick Clark:

    This will add a script that runs every day at 9:30am.

    exec('echo -e "`crontab -l`\n30 9 * * * /path/to/script" | crontab -');
    

    You may run into problems with permissions if you are running this script from a web server. To get around this, I would suggest a different approach.

    Here is one possible solution. Create a list of scripts that need to be run. You can save this in a text file or in a database. Create a script to read this list and run it every minute or every 5 minutes (using a cronjob). Your script will need to be smart enough to decide when to run the list of scripts and when to simply exit.

    You can do like this..

    Other links:

    Install a cron job with a php script

    How to invoke cron job from php script?

提交回复
热议问题