2016-09-21 43 views
0

我使用PEAR的Services_Facebook-0.2.14 SDK,並率先在Facebook.php以下行的失敗:爲什麼這個require_once失敗?

require_once 'Common.php'; 
require_once 'Services/Facebook/Common.php'; 
require_once 'Services/Facebook/Exception.php'; 

與日誌消息:

[21-Sep-2016 13:41:46 UTC] PHP Fatal error: require_once(): Failed opening required 'Common.php' (include_path='/home/thehanfw/php/Services') in /home/thehanfw/php/Services/Facebook.php on line 23

在我的Facebook API客戶端,我用下面的行要訪問SDK:

ini_set("include_path", "/home/thehanfw/php/Services"); 
require_once "Facebook.php"; 

我已經明確地設置了包含路徑,就像這樣絕望了,befo我的應用程序甚至會發現Facebook.phpCommon.php文件存在,並且我已將require_once 'Services/Facebook/Common.php';註釋掉,因爲Services已經是包含目錄,並且我得到的是與原始代碼完全相同的錯誤。

有趣的是,在我的客戶端應用程序中出現HTTP ERR_TOO_MANY_REDIRECTS錯誤之前,此錯誤在非常快速的連續記錄中大約記錄了20次。這是在共享主機上,使用PHP 5.6.22。

BREAKING:我覺得很有趣,我的客戶端應用程序正在我的dev的機器罰款,雖然,但後來我意識到,我只是在後來安裝在我的電腦上炸開PEAR,以及應用程序直接工作對一個SDK從Facebook下載,名爲php-graph-sdk-5.0.0。我不知道5.0.0 FB版本與0.2.14 PEAR版本是否相同,但是我已經從主機清除了PEAR廢話,並且安裝了FB SDK,它也可以在主機上運行。

+0

我認爲PHP沒有被指向正確的文件夾位置。你的include_path看起來沒問題(因爲Facebook.php駐留在那裏,它使得一個好的基本目錄,(我是否正確?))。所以,如果你從'require_once'Services/Facebook/Common.php'中刪除了「Services /'部分;'我認爲它會解決好。 – Werner

+0

我做了,它確實有效,然後我在'Common.php'中發現了同樣的問題。這是PEAR的代碼,而不是我的代碼,我對它非常不熟悉,所以我會通知他們,但不要自己嘗試修復它。 – ProfK

回答

0

PEAR軟件包代碼文件有require_once語句,只有在包含路徑中具有根包目錄時纔有效。 在你的情況下,包含路徑應​​至少包含/home/thehanfw/php/,因爲這是你手動提取軟件包的地方。

提取PEAR包手動is not recommended除非你真的知道你在做什麼:

We removed this section, because, today, manually installing a package requires a deeper understanding of the way how packages are organized and what happens during the installation process. You should read the section about the package.xml in the Developers Guide (package.xml and package.xml 2.0), if you really want install a package without the PEAR installer.

你顯然不這樣做,它失敗了。


PEAR包最近在2010年發佈,這是6年前。你最好用官方的API。