1

I have the following code:

$client = new GuzzleHttp\Client(
    array(
        'base_uri' => 'https://somesite.com'
    )
);

$response = $client->request('POST', '/api', [
         'form_params' => array(
         'action'   => 'getusers',
         'api_key'   => $_POST['key'],
         'id'       => $_POST['id']
    )
]);

When multiple users are accessing the same page with the following code above, other users waits for the first or recent request to finish before loading its request.

I'm not using any session.

I have tag curl because guzzle is built on top of it. Maybe it has something to do with it?

Any workaround for this?

using xhr won't fix it because the site I'm requesting for the API does not accept other origins.

John Pangilinan
  • 953
  • 1
  • 8
  • 25
  • Don't think one request should cause other requests to hang unless (a) you've ate up all the server resources, or (b) you're hitting some kind of process limit. I believe this would be controlled by nginx or apache or php-fpm. Which are you using? If Apache, maybe look at [MaxClients](https://stackoverflow.com/a/1430890/65387) setting. – mpen Jul 28 '17 at 02:29
  • Hi, im using nginx with php-fpm. Nope I don't think my server runs out of resources since no one is using it except me and my other pc. I can't find any `MaxClient` settings but the closes i found was `worker_connections` and I already set the `worker_connections` to `1024`. – John Pangilinan Jul 28 '17 at 02:54
  • I answer I posted early was not correct, I thought it worked but a minutes later it started blocking other requests. – John Pangilinan Jul 28 '17 at 05:10
  • You sure some users are waiting for other users? Maybe the API endpoint you're hitting is throttling you? – mpen Jul 29 '17 at 01:02
  • Yes it is waiting, We tested 2 pc, When the first pc request the page, the 2nd pc waits for the first pc request to finish before it loads. I think it waits for the guzzle requesting the page from an external api, maybe it has something to do with curl? – John Pangilinan Aug 07 '17 at 08:45
  • It wouldn't matter that you tried with two different client PCs, Guzzle is running on the server. Both requests are coming from the same IP. – mpen Aug 08 '17 at 07:27

1 Answers1

1

Check available PHP processes if you are using PHP FPM. It has a status page (the setup is described there) to get this information.

If all the workers are busy, then client's requests will wait. You need to increase the amount of workers to be able to process more requests at once.

Alexey Shokov
  • 4,775
  • 1
  • 21
  • 22
  • I mean [`process.max`](http://php.net/manual/en/install.fpm.configuration.php#process-max) in PHP-FPM config (`/etc/php/7.0/fpm/pools/www.conf` or something, depends on your system). – Alexey Shokov Aug 08 '17 at 10:41