Laravel server hangs whenever I try to request localhost:8000/any using guzzle

guzzle localhost
laravel guzzle
gazelle laravel
why use guzzle
guzzlehttp
include guzzle in laravel
laravel-guzzle service provider
cara install guzzle laravel

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?

try this.
namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Route;
use App\User;

class UserController extends Controller
{

    //use AuthenticatesUsers;
    protected function login(Request $request)
    {

         $request->request->add([
                'grant_type'    => 'password',
                'client_id'     => '3',
                'client_secret' => '6BHCRpB4tpXnQvC1DmpT7CXCSz7ukdw7IeZofiKn',
                'scope' => '*'
            ]);

        // forward the request to the oauth token request endpoint
        $tokenRequest = Request::create('/oauth/token','post');
        return Route::dispatch($tokenRequest);
    }

}

Guzzle Hang when trying to access my url · Issue #1857 · guzzle , file_get_contents() doesn't work on localhost for some reason on dev server (port Navigating in borwser to http://localhost:8000/forum/api.php works fine. 4 Laravel server hangs whenever I try to request localhost:8000/any using guzzle Feb 19 '18. 2 Laravel passport authentication and token generation Feb 19 '18.

I ended up solving it by using wamp virtualhost instead of php artisan serve. No idea why it doesn't work with localhost though.

I will mark as accepted any answer that explains why this happens and if it's possible to use php artisan server and guzzle in this example. But for now wamp works.

EDIT: someone was kind enough to explain why it wouldn't work.

In https://github.com/guzzle/guzzle/issues/1857#issuecomment-506962175

The reason for this is php artisan serve is a single thread application. So when we use guzzle to request from it to itself, it basically just tries to finish guzzle request (as a client) first then come to finish that request (as a server), which is impossible.

More info about this: https://php.net/manual/en/features.commandline.webserver.php

Also this answer:

When making calls to itself the thread blocked waiting for its own reply. The solution is to either seperate the providing application and consuming application into their own instance or to run it on a multi-threaded webserver such as Apache or nginx.

Request to API on localhost freeze, When I use GuzzleHttp and send the request, my laravel program is interrupted and I will and I will stop the server and run it again. if use online api or just use localhost without port number not problem and work. but when use port 8000 or any port , laravel app hang up . try to use base_uri as bellow Hi sir, im not sure if this is a bug but, it hangs my app whenever i try to access my local url using guzzle as you can see to the attach image it stuck into pending whenever i hit my button to my app: and here is the backend controller

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.

GuzzleHttp hang up my laravel app, The build in PHP development server (artisan: serve) is single threaded so will hang, for example http://localhost:8000 will not work. Guzzle Hang when trying to access my url · Issue #1857 · guzzle , Hi sir, im not sure if this is .it is continuesly , using laravel GuzzleHttp .i am not gettin any error but my page is will it work. Whenever I try to upgrade from phpspec ~2.0 to ~3.0, compose hangs forever at the "Resolving dependencies through SAT" stage. Note that setting it to a specific version, as mentioned to solve the problem by @anoopmd, did not resolve the issue in my case.

laravel guzzle not work page stuck on reloading, as you can see to the attach image it stuck into pending whenever i hit my button to my i use laravel for my backend and trying to make a login authentication using So when we use guzzle to request from it to itself, it basically just tries to finish guzzle request (as a client) first then come to finish that request (as a server​),  I'm trying to add in the ability to restart Apache once it completes but then my script hangs (I'm guessing because it loses connection from the web server). Is there a way to send the service httpd restart command and return without waiting?

Guzzle Hang when trying to access my url - guzzle, Laravel server hangs whenever I try to request localhost:8000/any using guzzle. If I make any request to http://localhost:8000 or http://127.0.0.1:8000 it hangs on  actually trying convert html content pdf using nreco pdf converter, however, line of code pdfdoc.generatepdf(htmlcontent); unable through on azure web app, works on dev environment. question cloud service should go for? azure apps (former websites) operate in restricted (partial-trust) environment , wkhtmltopdf.exe (that internally used nreco pdfgenerator wrapper) cannot executed in case

Making Requests, Laravel's wrapper around Guzzle is focused on its most common use cases and The get method returns an instance of Illuminate\Http\Client\Response Of course, it is common when using POST , PUT , and PATCH to send additional data with the request if a client or server error occurs, you may use the retry method. For my remote work, I use an old Plantronics wireless headset that's since been discontinued more than I use my actual podcasting mic, and if I wasn't using my Sony camera for YouTube and streaming, I'd still be using my old Logitech C930e webcam (although, if I had to buy it today, I would try the Razer Kiyo).

Comments
  • i had exactly the same issue and solved it exactly the same way if someone could explain this it would be awesome