Guzzle: transfer closed, bytes remaining to read

February 2017 · 1 minute read

Sometimes I get this annoying error, but a Stackoverflow post already gave some advice how to solve it for curl. In this post, I’ll show you how you can adopt this solution for guzzle.

Basically, you just have to set the values as your default request options like this:

$client = new GuzzleHttp\Client(
  [
    'curl' => [
      CURLOPT_TCP_KEEPALIVE => 10,
      CURLOPT_TCP_KEEPIDLE => 10
    ]
  ]);

But you can also set them on a on-request basis:

$client->request('GET', '/', [
    'curl' => [
        CURLOPT_TCP_KEEPALIVE => 10,
        CURLOPT_TCP_KEEPIDLE => 10
    ]
]);
© Christian Hotz-Behofsits. All rights reserved.