Failed opening required 'HTTP/Request2.php' (include_path='.;C:\php5\pear')

cj333 picture cj333 · Dec 19, 2010 · Viewed 30.8k times · Source

everyone. I have some trouble in pear. I test in my localhost(my localhost path is e:\www), my system is windows xp sp3, My php version is 5.2.11, the path is C:\Program Files\phpStudy\PHP5, I run go-pear.bat in this path and finished install the pear, now the pear path is in C:\Program Files\phpStudy\PHP5\PEAR(under the folder contains .channels,.registry, OS, PEAR, .depdb, .depdblock, .filemap, .lock, go-pear.phar), then I run C:\Program Files\phpStudy\PHP5\PEAR_ENV.reg and modify the php.ini,

; Windows: "\path1;\path2"
include_path = ".;C:\Program Files\phpStudy\PHP5\PEAR"

After restart the apache, I test a simple code which copy from pear's website.

<?php
require_once 'HTTP/Request2.php';

$request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET);
try {
    $response = $request->send();
    if (200 == $response->getStatus()) {
        echo $response->getBody();
    } else {
        echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
             $response->getReasonPhrase();
    }
} catch (HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?> 

but it return

Warning: require_once(HTTP/Request2.php) [function.require-once]: failed to open stream: No such file or directory in E:\www\ct\1.php on line 2

Fatal error: require_once() [function.require]: Failed opening required 'HTTP/Request2.php' (include_path='.;C:\php5\pear') in E:\www\ct\1.php on line 2

What's wrong is it? How to solve? Thanks.

Answer

Night Owl picture Night Owl · Feb 14, 2011

You need to install the PEAR package http_request2.

You can try the command...

pear install http_request2

as supplied by cweiske but it may fail with an error like...

Failed to download pear/http_request2 within preferred state 
"stable", latest release is version 0.5.2, stability "alpha", 
use "channel://pear.php.net/http_request2-0.5.2"

If you see that error you will need to install with the command...

pear install "channel://pear.php.net/http_request2-0.5.2"

This may generate a dependency error regarding the Net_URL2 package like....

Failed to download pear/Net_URL2 within preferred state "stable", latest 
release is version 0.3.1, stability "beta", 
use "channel://pear.php.net/Net_URL2-0.3.1" to install
pear/HTTP_Request2 requires package "pear/Net_URL2" (version >= 0.2.0)

If you see such an error issue the command...

pear install "channel://pear.php.net/Net_URL2-0.3.1"

and then re-issue the command...

pear install "channel://pear.php.net/http_request2-0.5.2"

and you should be all set. The "state" of these packages may change over time so the exact versions in the commands above will also likely change and at some point the command pear install http_request2 may begin working on its own.

Good luck.