PHP Cron Job:包括文件不起作用? [英] PHP Cron Job: Including file not working?
问题描述
我每天晚上都执行cron作业,但是由于某种原因,这就是说我尝试包含的文件不存在:
i run a cron job every night, but for some reason, it is saying that the file i try to include is inexistant:
Warning: require(../includes/common.php): failed to open stream: No such file or directory in /home/fini7463/public_html/cron/journeyNotifications.php on line 2
Fatal error: require(): Failed opening required '../includes/common.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/fini7463/public_html/cron/journeyNotifications.php on line 2
代码如下:
set_include_path('/home/fini7463/public_html/includes/');
require 'common.php';
文件 common.php的位置如下
the file 'common.php' is located as follows
public_html => cron => journeyNotifications.php
=> includes => common.php
我什至设置了include路径(如代码所示),但我仍然得到这个错误。
i even set the include path (as shown in the code), but i am still getting this error. what could the problem be?
谢谢!
推荐答案
请执行 require('../ includes / common.php')
,相对于当前工作目录遍历路径。
If you do require('../includes/common.php')
, the path is traversed relative to the current working directory.
如果执行 require('common.php')
,则会在包含路径中搜索文件,并且
If you do require('common.php')
, the file is searched in the include path, and in the directory of the script which calls the require().
要解决此问题,请首先在crontab中更改目录:
To solve this, first change directory in your crontab:
cd /home/fini7463/public_html; php -f cronjob.php
这篇关于PHP Cron Job:包括文件不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!