0

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.

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • I think PHP is not being pointed to the right folder location. Your include_path looks okay (as Facebook.php resides there it makes a good base dir, (am i correct?)). So, if you remove the part `Services/` from `require_once 'Services/Facebook/Common.php';` I think it will resolve ok. – Werner Sep 21 '16 at 15:17
  • I did, and it did work, then I found the same problem in `Common.php`. That is PEAR's code, and not mine at all, and I am very unfamiliar with it, so I will inform them, but not try and fix it myself. – ProfK Sep 22 '16 at 03:21

1 Answers1

1

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.

cweiske
  • 30,033
  • 14
  • 133
  • 194