The Thread class
(PECL pthreads >= 2.0.0)
Introduction
When the start method of a Thread is invoked, the run method code will be executed in separate Thread, asynchronously.
After the run method is executed the Thread will exit immediately, it will be joined with the creating Thread at the approriate time.
Warning
Relying on the engine to determine when a Thread should join may cause undesirable behaviour; the programmer should be explicit, where possible.
Class synopsis
/* Methods */
/* Inherited methods */
}Table of Contents
- Thread::detach — Execution
- Thread::getCreatorId — Identification
- Thread::getCurrentThread — Identification
- Thread::getCurrentThreadId — Identification
- Thread::getThreadId — Identification
- Thread::globally — Execution
- Thread::isJoined — State Detection
- Thread::isStarted — State Detection
- Thread::join — Synchronization
- Thread::kill — Execution
- Thread::start — Execution
Коментарии
<?php
class workerThread extends Thread {
public function __construct($i){
$this->i=$i;
}
public function run(){
while(true){
echo $this->i;
sleep(1);
}
}
}
for($i=0;$i<50;$i++){
$workers[$i]=new workerThread($i);
$workers[$i]->start();
}
?>
<?php
# ERROR GLOBAL VARIABLES IMPORT
$tester=true;
function tester(){
global $tester;
var_dump($tester);
}
tester(); // PRINT -> bool(true)
class test extends Thread{
public function run(){
global $tester;
tester(); // PRINT -> NULL
}
}
$workers=new test();
$workers->start();
?>