2

First I installed the curl extension for PHP:

$ sudo pacman -S php-curl

and

$ grep curl /etc/php/php.ini
extension=curl.so

Then I installed the PHP PEAR

$ sudo pacman -S php-pear

Having now installed pear, I have also installed PECL, and should now be able to install the php_http extension.

$ pecl install php_http

and

$ grep http.so /etc/php/php.ini
extension=http.so

The http.so is found in the folder /usr/lib/php/moduels/ and latter copied to the folder /usr/lib/http/modules/ .

Now, as far as I know, this should have installed the php_http extension, but when I try to

$req = new HttpRequest();

I get the error

Fatal error: Class 'HttpRequest' not found in /srv/http/webcrawler/nettocrawl.php on line 4 
1

PECL HTTP 2.0+

The latest version of pecl_http introduces the http namespace. so HttpRequest will no longer be available. Follow php's documentation for using namespace, and checkout the supplied phpunit directory for usage & examples.

$req = new http\Client\Request();

Or a more preferred way, that allows for backwards support

use http\Client\Request as HttpRequest;
$req = new HttpRequest();

Else

Sometimes PECL extensions might not get installed correctly. This can happen if your mixing pacman packages and pecl extensions, but it's very rare. I recommend installing pecl_http by hand.

Grab source

shell ~> curl -o pecl_http.tar.gz http://pecl.php.net/get/pecl_http
shell ~> tar zvxf pecl_http.tar.gz
shell ~> cd pecl_http

Configure, Compile, and Test

shell ~/pecl_http> phpize
shell ~/pecl_http> ./configure
shell ~/pecl_http> make
shell ~/pecl_http> make test

Install

shell ~/pecl_http> make install

This will output the directory http.so will be installed. In my case, it's /usr/lib/php/<timestamp>/. A helpful note.

php.ini & Test

Edit php.ini file, and add the http.so extension.

shell ~> php -m | grep http

If http is not displayed, re-edit the php.ini, and the extensions full path;

extension=/usr/lib/php/<timestamp>/http.so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.