leak
opened this issue · comments
Hi,
- Thank you for amazing product (amp)
- Code:
Amp\run(function () {
$client = new \Amp\Redis\Client("tcp://localhost:6379");
\Amp\once(function() use ($client)
{
print("close\n");
$client->close();
}, 2000);
\Amp\repeat(function() use ($client)
{
print("repeat\n");
}, 1000);
});
__destruct
on$client
is never called, only if loop is stopped,
but i useRedis
in a Tcp Server Loop, and open for each incoming connection a new Redis connection (may be not the best approach), after Tcp connection is closed I try to close Redis connection, but it seams like not dealloc-ing
@umbri: Your variable client
is still in scope here, so PHP doesn't clean it up, but the connection should be closed. You can reuse the same connection for every client.
@kelunik Thank you for help.
As I say this is not the best approach, I think I should do something like a connection pool but, I want to be able to free memory, Currently I have ~ 30K connections opened simultaneous. I try to:
...
\Amp\once(function() use ($client)
{
print("close\n");
$client->close();
$client = null; //unset($client);
}, 2000);
...
but $client is not dealloc-ing
I think this is a bug.
Any suggestions ?
I think I should do something like a connection pool
You don't need a connection pool, just using one connection is fine as long as you don't use the blocking commands.
The following code calls __destruct
as expected.
<?php
require_once __DIR__ . "/vendor/autoload.php";
Amp\run(function () {
$client = new \Amp\Redis\Client("tcp://localhost:6379");
\Amp\once(function() use (&$client) {
print("close\n");
$client->close();
$client = null;
gc_collect_cycles();
}, 2000);
\Amp\repeat(function () {
print("repeat\n");
}, 1000);
Amp\once(function () {
print "stop" . PHP_EOL;
Amp\stop();
}, 5000);
});
Thank you.