http-client
http-client copied to clipboard
Over file descriptor when not get body for response
Payload will not been destruct from memory when not read body.
while (true) {
$url = 'Some short url';
$response = $client->request(new Request($url));
echo $response->getHeader('Location');
}
You can add a static counter on Payload construct and destruct, will find out.
How is it currently fixed in the own code?
Call $response->getBody()->buffer() or $response->getBody()->close() after read response.
May be should use WeakReference in some stream resource, to make it can auto destruct.
I can't reproduce this with your script, same for the counters, seems to work well and the body is properly GCed.
<?php declare(strict_types=1);
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Request;
require __DIR__ . '/../.helper/functions.php';
while (true) {
try {
// Instantiate the HTTP client
$client = HttpClientBuilder::buildDefault();
// Make an asynchronous HTTP request
$response = $client->request(new Request($argv[1] ?? 'https://httpbin.org/user-agent'));
$header = $response->getHeader('Location');
echo memory_get_usage(true) . PHP_EOL;
} catch (HttpException $error) {
echo $error;
}
}
Try this, use a single pool instance.
I'm now using php8.1 with ev extension on ubuntu 20.04 amd64.
<?php declare(strict_types=1);
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Request;
require __DIR__ . '/../.helper/functions.php';
// Instantiate the HTTP client
$client = HttpClientBuilder::buildDefault();
while (true) {
try {
// Make an asynchronous HTTP request
$response = $client->request(new Request($argv[1] ?? 'https://httpbin.org/user-agent'));
$header = $response->getHeader('Location');
echo memory_get_usage(true) . PHP_EOL;
} catch (HttpException $error) {
echo $error;
}
}