Services_Openstreetmap icon indicating copy to clipboard operation
Services_Openstreetmap copied to clipboard

Can't find HTTP/Request2.php

Open Rudloff opened this issue 9 years ago • 7 comments
trafficstars

Hello,

I installed your library with Composer. I get this error when trying to run it:

PHP Warning:  require_once(HTTP/Request2.php): failed to open stream: No such file or directory in /home/pierre/www/openvegemap/vendor/kenguest/services-openstreetmap/Services/OpenStreetMap.php on line 19
PHP Fatal error:  require_once(): Failed opening required 'HTTP/Request2.php' (include_path='/home/pierre/www/openvegemap/vendor/pear/pear_exception:/home/pierre/www/openvegemap/vendor/pear/log:/home/pierre/www/openvegemap/vendor/kenguest/services-openstreetmap:.:/usr/share/php:/usr/share/pear') in /home/pierre/www/openvegemap/vendor/kenguest/services-openstreetmap/Services/OpenStreetMap.php on line 19

Here is my code:

<?php
require_once 'vendor/autoload.php';
$osm = new Services_OpenStreetMap();

Rudloff avatar Sep 19 '16 13:09 Rudloff

Note that it works if I install http_request2 with PEAR. But I think Composer should be able to autoload it without having to use PEAR.

Rudloff avatar Sep 19 '16 14:09 Rudloff

This install and demo works for me. What version did you try to install?

vagrant@vagabond:~/osm$ cat > composer.json { "require": { "kenguest/services-openstreetmap": "*" } } vagrant@vagabond:~/osm$ composer update You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug Loading composer repositories with package information Updating dependencies (including require-dev)

  • Installing pear/pear_exception (v1.0.0) Loading from cache
  • Installing pear/log (1.12.9) Loading from cache
  • Installing pear/net_url2 (v2.2.1) Loading from cache
  • Installing pear/http_request2 (v2.2.1) Loading from cache
  • Installing kenguest/services-openstreetmap (V0.5.0) Loading from cache

pear/log suggests installing pear/db (Install optionally via your project's composer.json) kenguest/services-openstreetmap suggests installing pear/cache (*) Writing lock file Generating autoload files vagrant@vagabond:~/osm$ cat > f.php

getNode(545109)->getUser()); vagrant@vagabond:~/osm$ php f.php string(5) "izzor" vagrant@vagabond:~/osm$

kenguest avatar Sep 19 '16 22:09 kenguest

I installed 0.5.0. Are you sure in your case the library is loaded from vendor/pear/http_request2/HTTP/Request2/ and not /usr/share/php/HTTP/Request2/?

Rudloff avatar Sep 20 '16 09:09 Rudloff

It seems you have to add the following line to your composer.json to get HTTP/Request2 auto-loaded: "include-path": [ "vendor/pear/http_request2" ]

(But that is just a workaround)

FireLizard avatar Oct 23 '16 22:10 FireLizard

I had the same problem, and found this workaround (the methods mentioned here haven't worked for me): Switch to directory ~/vendor/kenguest/services-openstreetmap and create a symboli link ln -s ../../pear/http_request2/HTTP HTTP

sascha-hendel avatar Mar 28 '18 08:03 sascha-hendel

I solved this by adding this line

set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/pear/http_request2');

before $osm = new Services_OpenStreetMap();

But then I ran into an issue with http now redirecting to https - and even manually changing to https in the config file it still had an issue (though that could potentially just be on my local dev machine). Realized it was probably just as easy to use the API directly as describe at https://wiki.openstreetmap.org/wiki/API_v0.6#API_calls

winternet-studio avatar Sep 22 '19 21:09 winternet-studio

HTTP_Request2 2.4+ no longer sets include_path when installed with composer. The suggested approach is to conditionally include the file if autoloading does not work (this will work with PEAR installation, composer installation and even mix of those):

if (!class_exists('HTTP_Request2', true)) {
    require_once 'HTTP/Request2.php';
}

See also pear/HTTP_Request2#18

sad-spirit avatar Jun 07 '22 10:06 sad-spirit