If I make any request to http://localhost:8000
or http://127.0.0.1:8000
it hangs on status pending. (Exactly as here https://github.com/guzzle/guzzle/issues/1857)
I was told that it isn't related to guzzle and that I should better ask about it here.
I stumbled upon this problem while following laravel.com/docs/5.4/passport
This is the code that hangs:
$response = $http->post('http://your-app.com/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 'client-id',
'client_secret' => 'client-secret',
'redirect_uri' => 'http://example.com/callback',
'code' => $request->code,
],
]);
I tried making GET and POST request to working API routes (tested with postman) and it still hangs when calling the same routes using guzzle.
So is there a way to make requests to my own API while using php artisan serve
?
First one is run your Laravel server on other port with the bellow command. Second way is to kill service which runs on the port 8000 and then run your Laravel application on port 8000. For that first run bellow command, it will display servies which runs on the port.
In Laravel you have to explain that your URL will hit controller@function. What is local host 8080? Short answer: “this machine, port 8080”. Slightly longer short answer: an application, typically a web application, that is running on the user’s own computer, utilizing UDP or typically TCP port 8080.
The reason why it does not work is that php artisan serve uses the PHP built-in web server and this is single threaded. So if you run your application it cannot make another request (your Guzzle request) until it finishes the initial request. That is why it hangs (as mentioned here ).
So if you run your application it cannot make another request (your Guzzle request) until it finishes the initial request. That is why it hangs (as mentioned here ). One solution is (as you pointed out) to use a real webserver that is multi-threaded.
Carl has a great solution to this. If you are looking for a quick fix to test your updates - you can get this done by opening up two command prompts. The first would be running php artisan serve
(locally my default port is 8000 and you would be running your site on http://localhost:8000
). The second would run php artisan serve --port 8001
.
Then you would update your post request to:
$response = $http->post('http://localhost:8001/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 'client-id',
'client_secret' => 'client-secret',
'redirect_uri' => 'http://example.com/callback',
'code' => $request->code,
],
]);
This should help during your testing until you are able to everything on server or a local virtual host.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With