2011-05-17 41 views
0

我花了几天的时间还是无法弄清楚这一点。 public_html下php路径,cron和cpanel

我有以下文件结构:

cron_jobs/file.php contains - > include('../base/basefile.php') 
base/basefile.php contains - > include('baseSubFile.php') 

当我运行

/pathtophp/php -f ~/public_html/cron_jobs/file.php

它工作正常,但是当我复制相同的命令到的cPanel的cron,我得到错误说

'basesubfile.php' can't be found

请帮忙。为你的PHP文件是

回答

2

的Cron不会从同一目录中运行,所以你需要先更改它:用cron脚本打交道时

cd /home/user/public_html/cron_jobs/ && /pathtophp/php -f file.php 

我建议的完整路径与~为了避免混淆

1

你应该使用

include dirname(__FILE__) . '/../base/basefile.php'; 

include dirname(__FILE__) . '/baseSubFile.php'; 

The function dirname返回上级目录的路径

0

简单地说这在你的PHP脚本的顶部:

chdir(dirname(__FILE__));