簡體   English   中英

php 腳本 require() 語句在從瀏覽器運行時獲取文件,但在從 Plesk CRON 作業運行時不獲取文件

[英]php script require() statement fetches file when running from browser but not when running from Plesk CRON job

我有一個任務腳本,如果我通過從瀏覽器訪問 php 文件來運行它,它可以正常工作。 但是,當我嘗試通過 Plesk Task Scheduler 運行它時,它會失敗並出現無法加載require()文件的致命錯誤。

require 語句是一個簡單的相對路徑:

require('../../../app.config.php');

錯誤是:

PHP Fatal error: require(): Failed opening required '../../../app.config.php'

我認為這可能與include_path相關,但我對此include_path ,因此有點迷失。

任何幫助都會很棒!

當前目錄解析的相對路徑。 解決方案:獲取腳本目錄並結合相對路徑,例如:

 require(dirname(__FILE__).'/../../../app.config.php');

您需要使用絕對路徑。 如果直接調用腳本或將腳本包含在另一個腳本中,則可能會產生不同的相對路徑。

例如:

a.php is on path A/B/C the ../../ will result in in A/
b.php is on path A/B/C/D, if it inlcudes the a.php then the ../../ on a.php will result in A/B/.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM