doujiufutaog59220 2011-01-22 01:02
浏览 26

如何通过PHP(而不是CPanel)设置cron作业?

How to set up a cron job via PHP (not CPanel)?

  • 写回答

5条回答 默认 最新

  • dongyan5641 2011-01-22 01:07
    关注

    Most Linux systems with crond installed provides a few directories you can set up jobs with:

    /etc/cron.d/
    /etc/cron.daily/
    /etc/cron.weekly/
    /etc/cron.monthly/
    ...
    

    The idea here is to create a file in one of these directories. You will need to set the proper permissions/ownership to those (or one of those) directories so that the user launching the PHP script can write to it (Apache user if it's a web script, or whatever CLI user if CLI is used).

    The easiest thing is to create an empty file, assign proper permission/ownership to it, and have the PHP script append/modify it.

    Per example:

    $ touch /etc/cron.d/php-crons
    $ chown www-data /etc/cron.d/php-crons
    

    Then in PHP:

    $fp = fopen('/etc/cron.d/php-crons', 'a');
    fwrite($fp, '* 23 * * * echo foobar'.PHP_EOL);
    fclose($fp);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度