简体   繁体   English

在PHP的cron作业中包含路径错误

[英]include path error in the cron job in php

i have the functionality to generate XML file on each day using php. 我有使用php每天生成XML文件的功能。

This works fine in the browser.but it doesn't work in the cron job. 这在浏览器中工作正常,但在cron作业中不起作用。

The cron give me error for the required once and Fatal error.And it stops the execution of my cron job. cron给了我一次必要的错误和致命错误,并停止了我的cron作业的执行。 the included file is also including other files. 包含的文件还包括其他文件。

the error which i am getting is like, 我得到的错误是,

Warning : require_once(/common/configs/config_local.inc.php) [function.require-once]: failed to open stream: No such file or directory in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281 警告 :require_once(/common/configs/config_local.inc.php)[function.require-once]:无法打开流: /home/wwwsite/public_html/sitename/common/configs/config.inc中没有此类文件或目录.php281

Fatal error : require_once() [function.require]: Failed opening required '/common/configs/config_local.inc.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281 致命错误 :require_once()[function.require]:无法打开所需的'/common/configs/config_local.inc.php'(include_path ='。:/ usr / lib / php:/ usr / local / lib / php')在第281行的/home/wwwsite/public_html/sitename/common/configs/config.inc.php中

any one having solution to this issue? 有谁能解决这个问题?

It's telling you it can't find '/common/configs/...' note the absolute path there with the first character being a '/'. 它告诉您找不到'/ common / configs / ...',请注意此处的绝对路径,第一个字符为'/'。

You can either make it a relative path from where you are defining it, or put the prefix in there as well ('/home/wwwsite/public_html/sitename/'), maybe with a variable ($sitebase ='/home/wwwsite/public_html/sitename/';) and prefix the include filename with it. 您可以将其设为定义它的相对路径,也可以在其中添加前缀('/ home / wwwsite / public_html / sitename /'),也许可以使用变量($ sitebase ='/ home / wwwsite / public_html / sitename /';),并在包含文件名前面加上前缀。

The reason it is working on a website, but not on the command line could be one of a few ways. 它可以在网站上运行,但不能在命令行上运行的原因可能是以下几种方法之一。 Most obvious is that the php.ini include_path for the CLI (command line interface) doesn't include the '.' 最明显的是CLI(命令行界面)的php.ini include_path不包含“。”。 for checking from the current directory. 用于从当前目录检查。 There's also a good reason it doesn't have it by default. 还有一个很好的理由默认情况下没有它。 The other way is maybe your code puts the ..../sitename/ directory into the include_path - or otherwise sets up the files to be included automatically. 另一种方法是,您的代码可以将.... / sitename /目录放入include_path-否则可以设置要自动包含的文件。

i have got the solution, 我有解决方案,

curl yoursitename/yourfilename.php > /dev/null 2>&1 卷曲yoursitename / yourfilename.php> / dev / null 2>&1

This has run my cron job as i have set without any error 这已经按照我的设置运行了我的cron工作,没有任何错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM