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

4

14

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.

Defeatist answered 19/12, 2010 at 14:16 Comment(1)
You are missing the file e:\www\HTTP\Request2.phpBabbler
K
28

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.

Kinsley answered 14/2, 2011 at 3:54 Comment(5)
this problem occupied me a long time, now it works, Thanks Night OwlDefeatist
Thanks for this answer. It helped me fix an issue I had when using Pear to install PHPUnit on Ubuntu NattyClavicorn
Most excellent, especially the tip on using pear install "channel ... worked a treat.Opinion
I have same problem regarding http/request2 for php on windows Azure. I run all the commands for all it generates "No realease available for pacakage ....Arand
FYI all: had to sudo to get this working on one of my machinesCostrel
D
2

You need to install the HTTP_Request2 package from pear:

pear install http_request2

Then it should work.

Danelaw answered 3/1, 2011 at 15:48 Comment(0)
C
1

I had similar problem on centos. If above things don't work, follow this patch

http://www.angeloluput.com/php-planet/pear-on-php-5-5-could-not-extract-package-xml

Patch was not working so I have to manually apply the patch. and it worked.

Countrified answered 28/9, 2014 at 9:55 Comment(0)
M
1

try it with composer

$ composer require pear/http_request2

using Window you may try

php composer.phar require pear/http_request2

with allow all dependencies parameter

Maximalist answered 2/3, 2022 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.