Pool::activeCount
(PHP 8.6+, True Async 1.0)
php
public Pool::activeCount(): intGibt die Anzahl der Ressourcen zurueck, die derzeit in Verwendung sind (ueber acquire() oder tryAcquire() erworben und noch nicht ueber release() zurueckgegeben).
Parameter
Diese Methode nimmt keine Parameter entgegen.
Rueckgabewert
Die Anzahl der aktiven Ressourcen.
Beispiele
Beispiel #1 Aktive Ressourcen zaehlen
php
<?php
use Async\Pool;
$pool = new Pool(
factory: fn() => new \stdClass(),
max: 5
);
echo $pool->activeCount() . "\n"; // 0
$r1 = $pool->acquire();
$r2 = $pool->acquire();
echo $pool->activeCount() . "\n"; // 2
$pool->release($r1);
echo $pool->activeCount() . "\n"; // 1Beispiel #2 Pool-Statistiken anzeigen
php
<?php
use Async\Pool;
function poolStats(Pool $pool): string
{
return sprintf(
"Pool: gesamt=%d, aktiv=%d, unbenutzt=%d",
$pool->count(),
$pool->activeCount(),
$pool->idleCount()
);
}Siehe auch
- Pool::idleCount --- Anzahl unbenutzter Ressourcen
- Pool::count --- Gesamtanzahl der Ressourcen