Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to use Guzzle on Phalcon

Hi, I will love to consume API with guzzle on phalcon how do I go about. I already grab the guzzle from packagist using composer but give error that the class does not exist when calling it.

Thanks



42.3k
Accepted
answer

You'll have to include the vendor/autoload.php file of composer in your project.

Thanks for the reply but how can I include vendor/autoload.php to the project. Because I added the file to index.php in pub folder which gave Warning: include(D:\site\htdocs\FirstApp/app/vendor/autoloader.php): failed to open stream: No such file or directory in D:\site\htdocs\FirstApp\public\index.php on line 32 Thanks

You'll have to include the vendor/autoload.php file of composer in your project.

edited Jan '17

Best approach for this is to autoload external package with Phalcon Loader as it is much faster than plain PHP require, actually you only load Composer's autoloader and voila, all your external dependencies are met.

//Include composer autoloader - Phalcon way as of 3.0.x
$loader->registerFiles([APP_PATH . '/vendor/autoload.php']);

(considering your project has been Bootstrapped properly, or just put absolute path instead of APP_PATH constant).

And in general, curl is faster as http client. You can even use OOP wrapper.... Guzzle is nice but IMHO puts too much overhead.