Why does this require_once fail?

436 Views Asked by At

I am using PEAR's Services_Facebook-0.2.14 SDK, and the first of the following lines in Facebook.php fails:

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

with the log message:

[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

In my Facebook API client, I use the following lines to access the SDK:

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

I have set the include path explicitly like this out of desperation, before my app would even find Facebook.php. The Common.php file is present, and I have commented out the require_once 'Services/Facebook/Common.php'; because Services is already the include directory, and I was getting exactly the same error with the original code.

Interesting as well is that this error is logged about 20 times in very quick succession before I get an HTTP ERR_TOO_MANY_REDIRECTS error in my client app. This is on a shared host, with PHP 5.6.22.

BREAKING: I found it funny that my client app was working fine on my dev machine though, but then I realised I had only later installed the blasted PEAR on my PC, and the app was working against an SDK directly downloaded from Facebook, named php-graph-sdk-5.0.0. I don't know if the 5.0.0 FB version vs. the 0.2.14 PEAR version, but that I've cleaned out the PEAR crap from my host, and installed the FB SDK, it works on the host as well.

1

There are 1 best solutions below

0
cweiske On

PEAR packages code files have require_once statements that only work when you have the root package directory in your include path. In your case the include path should include at least /home/thehanfw/php/, since that's where you (manually) extracted the package into.

Extracting PEAR packages manually is not recommended unless you really know what you are doing:

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.

You apparently do not, and it failed.


The PEAR package was last released in 2010, which is 6 years ago. You are better off with the official API.