doumaji6215 2014-08-28 00:05
浏览 22
已采纳

如何在php中正确包含cronjobs和正常执行的文件

So I have a script that updates all currency rates for my webshop. I am trying to have it run using a cronjob but when it's executed through a cronjob I get this error:

PHP Warning:  require(.../.../core/dbcon.php): failed to open stream: No such file or directory in /var/www/domain.com/wholesale/system/labs/cur.php on line 2
PHP Fatal error:  require(): Failed opening required '.../.../core/dbcon.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/domain.com/wholesale/system/labs/cur.php on line 2

I've also tried using the full link to include it but that seems to not work when running it manually and will also not work in cronjobs.

In the php file itself this is what I use to include it:

require(".../.../core/dbcon.php");

And when I manually run it, it returns all the currencies right, and updates them in the database.

How would I correctly require the file so it can execute using a cronjob and manually as well.

  • 写回答

1条回答 默认 最新

  • douxu2081 2014-08-28 00:14
    关注

    Try require("./../../core/dbcon.php"); or use absolute paths.

    UPDATE

    Answer has been updated - see comments below for more info.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?