php8.5
Home/ Manual/ pthreads / threaded/ Threaded::isRunning

Threaded::isRunning

PHP function Edit on GitHub ✎

(PECL pthreads >= 2.0.0)

State Detection

Description

Threaded::isRunning(): bool

Tell if the referenced object is executing

Parameters Parameters

Return Values

A boolean indication of state

Note

An object is considered running while executing the run method

Examples

Detect the state of the referenced object

php
<?php
class My extends Thread {
    public function run() {
        $this->synchronized(function($thread){
            if (!$thread->done)
                $thread->wait();
        }, $this);
    }
}
$my = new My();
$my->start();
var_dump($my->isRunning());
$my->synchronized(function($thread){
    $thread->done = true;
    $thread->notify();
}, $my);
?>

The above example will output:

output
bool(true)

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