We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



77.7k
Accepted
answer

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



1.2k

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.