dongzhanlu8890 2017-07-26 20:26 采纳率: 0%
浏览 67
已采纳

在CPanel上设置Cron作业以执行PHP脚本

As implied in the title, the Cron Job is supposed to execute a php file (update.php, to be specific). The php file then writes to a csv file stored in the same directory.

I have the time set to * * * * * so that it executes every minute. The command is written as follows: php -q /home//public_html/wallboard/update.php I don't believe this is causing any errors, though it also doesn't seem to write to the CSV file. When I visit update.php in a browser, however, it executes and writes to the CSV file immediately. I'm not experienced with Cron Jobs and I'm sure there's an issue, but I don't know what exactly that issue is. Let me know if you have suggestions/questions. Any help is appreciated!

Current Command:

* * * * * usr/bin/php -q /home/<user>/public_html/wallboard/update.php

update.php:

<?php

include('lib/HelpDeskView.php');
include('lib/WallboardDisplay.php');
include('helpdesk.csv');
$helpdesk = new HelpDeskView();
$text="
test,test,test";
file_put_contents( "helpdesk.csv" , $text, FILE_APPEND);
  • 写回答

4条回答 默认 最新

  • doutang7415 2017-07-27 20:14
    关注

    Since your script resides in your public_html directory you can use wget for your Cron Job

    wget -O - -q https://yoursite.com/wallboard/update.php
    

    -O - output is written to the standard output in this case it will go to the email address you specify in CPanel

    -q quiet mode

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dongque6377 2017-07-26 21:04
    关注

    IMHO the best way is to contact support and ask them about command line syntax.


    This is how I'm doing it at my linux server using cPanel.

    enter image description here

    This runs script.php which is stored in public root. Course, replace <username> in command line with your username.

    At another server I'm using same command line with /usr/bin/php instead of php at the beginning of line, but I'm aware that not all servers use same command line. Some require php-cli in command line instead of php, some don't "like" -f argument, etc. So try various combinations.

    To find more suggestions check out this SO topic too: Run a PHP file in a cron job using CPanel

    Important thing: When trying different commands wait at least a minute (this case) to see if it works because Cron doesn't fire your script immediately.

    评论
  • dsd57259 2017-07-26 21:44
    关注

    Try to execute the same command in PHP CLI and check if it gives you any error, you might be missing some libraries or references required for CLI execution.

    评论
  • duanhan9334 2019-08-27 17:54
    关注

    /usr/bin/php -d register_argc_argv=On /home/USERNAME/public_html/DOMAIN/artisan AMIR:HOME

    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 XIAO esp32c3 读取FDC2214的数据
  • ¥20 我用malloc申请了一块空间 判空显示指针不为null 但是在输出data指针所指的地址是缺全是0 空指针不能输入值进去数组为什么呀
  • ¥15 在工控机(Ubuntu系统)上外接USB蓝牙硬件进行蓝牙通信
  • ¥15 关于PROCEDURE和FUNCTION的问题
  • ¥100 webapi的部署(标签-服务器)
  • ¥20 怎么加快手机软件内部计时的时间(关键词-日期时间)
  • ¥15 C语言除0问题的检测方法
  • ¥15 为什么四分管的内径有的是16mm有的15mm,四分不应该是12.7mm吗
  • ¥15 macos13下 ios交叉编译的问题
  • ¥15 bgz压缩文件怎么打开