dragon188199 2015-08-23 05:13
浏览 73
已采纳

无法从cron运行php脚本

I am running LAMP system on ubuntu 14.04. I have an rss feed using php which runs every 1 hour and MySQL stores data. My php file used to run perfectly using php in cron some 15 days but its not working anymore

My cron is as below

0 * * * *  /usr/bin/php /var/www/html/rss.php >/dev/null

My php script is working perfectly from browser(firefox/chrome)

When I run the php script using wget in cron it works fine

0 * * * *  wget http://www.mywebsite.com/rss.php >/dev/null
  • 写回答

1条回答 默认 最新

  • duanlu7680 2015-08-23 14:13
    关注

    Your script is using relatives pathes.

    When you open this script in a browser it tries to find files in /var/www/html/.

    When you do it in the cron it tries to find files in /.

    Put this in the beginning of your script:

    define('ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
    

    Now change every relative include or opener:

    include ROOT . "db.php"
    

    ...

        if (($handle = fopen(ROOT . "tbcatlist.csv", "r")) !== FALSE)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵