php8.5
Home/ Manual/ pthreads / worker/ Worker::getStacked

Worker::getStacked

PHP function Edit on GitHub ✎

(PECL pthreads >= 2.0.0)

Gets the remaining stack size

Description

Worker::getStacked(): int

Returns the number of tasks left on the stack

Parameters Parameters

Return Values

Returns the number of tasks currently waiting to be executed by the worker

Examples

A basic example of Worker::getStacked

php
<?php
$worker = new Worker();

for ($i = 0; $i < 5; ++$i) {
    $worker->stack(new class extends Threaded {});
}

echo "There are {$worker->getStacked()} stacked tasks\n";

The above example will output:

output
There are 5 stacked tasks

Source: reference/pthreads/worker/getstacked.xml · from the official PHP manual (php/doc-en)