How to callback request until desired result in Guzzle?

Viewed 20

It works fine for a few calls, but if there are a large amount of data and I have to make the request multiple times This is my code:

function run() {
  global $client;
  $promise = $client->requestAsync('GET', 'http://localhost/test');
  $promise->then(
    function (ResponseInterface $res) {
      if ($res->getStatusCode() != 200 || $res->getBody() != "OK")  run();
      echo $res->getBody();
    },
    function (RequestException $e) {
      run();
    }
  );
  $response = $promise->wait();
  echo json_encode($response);
}

The amount of memory allowed is exhausted when calling me to run the code. It does not work as I would like. What I am doing wrong?

Any help is appreciated

0 Answers
Related