Executing php with crontab

后端 未结 6 993
误落风尘
误落风尘 2020-11-27 19:08

I\'m trying to run a php-script on a scheduled basis. So I\'d thought crontab was a good idea. The server I\'m using is on Linux which I\'m not that familiar with. So the pr

6条回答
  •  Happy的楠姐
    2020-11-27 19:46

    Is this a Linux system?

    In newer Linux distributions, there is
    actually a convienient crontab-setup system
    that doesn't require any entry in the crontab by the user. E.g in SuSE Linux, you have directories

    /etc/cron.hourly/
    /etc/cron.daily/
    /etc/cron.monthly/
    /etc/cron.weekly/
    

    Just put an invocation script (konno_php_start) in any of these directories, like

    /etc/cron.hourly/konno_php_start
    

    which is executable (chmod 755 or so) and contains:

    #!/bin/sh
    cd /var/www/some/path/
    php  script.php >> logfile.txt 2>&1
    

    and restart the cron daemon. Thats it.

    From the logfile, you'll see if your php interpreter
    will be found in the PATH. If not, change the line in /etc/cron.hourly/konno_php_start to

    /full/path/to/php  script.php >> logfile.txt 2>&1
    

    Regards

    rbo

提交回复
热议问题