PEAR module (HTTP_Request2) installed, but not recognized in php file?

2.3k Views Asked by At

I have HTTP_Request2 installed on my server; pear list shows it in the list of installed packages. But the following php file:

<?php

ini_set("include_path", '/path/to/php:' . ini_get("include_path"));

if (class_exists('HTTP_Request2')) {
    print("true");
} else {
    print("false");
}

...returns false. I've also tried replacing the ini_set line with

include '/path/to/php/HTTP/Request2.php';

...but I get the same result. Is there something I'm missing, or something else I can check?

1

There are 1 best solutions below

2
Alex Howansky On BEST ANSWER

Simply setting the include path doesn't implicitly give you access to the code. You need to either set the include path and then use relative includes:

ini_set("include_path", ...);
require_once 'HTTP/Request2.php';

Or just use fully qualified includes:

require_once '/path/to/HTTP/Request2.php';

That said, HTTP_Request2 is kinda old and I'd instead recommend using something like Guzzle via composer.