2011-05-17 38 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__));