Answer the question
In order to leave comments, you need to log in
How to use Guzzle from Symfony controller?
Hello saviors!
There is a task:
To give the controller the result from the external API.
I installed the Symfony Guzzle bundle to make a get request - this one .
And I have a controller that does this task:
/**
* @Route("/api/data")
*/
public function getData()
{
$url = "http://127.0.0.1:8000/test_guzzle";
$guzzle = $this->get('eight_points_guzzle.client.my_client');
$result = $guzzle->request('GET', $url);
return $this->json([$result]);
}
/**
* @Route("/test_guzzle")
*/
public function getThread(){
return new Response("HELLO!!!");
}
cURL error 28: Operation timed out after 30000 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
$url = "http://httpbin.org/get";
Answer the question
In order to leave comments, you need to log in
w_b_x The problem is not Guzzle.
You most likely started the server with the php app/console server:start command . This command uses the built-in php server. It, according to the documentation, can only process one request at a time.
php.net/manual/en/features.commandline.webserver.php
This is easy to verify if you open the following pages at the same time
/**
* @Route("/api", name="api")
*/
public function apiAction()
{
sleep(10);
return new Response('API page');
}
/**
* @Route("/test", name="test")
*/
public function testAction()
{
return new Response('Test page');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question