The Thread class

(PECL pthreads >= 2.0.0)

Введение

When the start method of a Thread is invoked, the run method code will be executed in separate Thread, in parallel.

After the run method is executed the Thread will exit immediately, it will be joined with the creating Thread at the appropriate time.

Внимание

Relying on the engine to determine when a Thread should join may cause undesirable behaviour; the programmer should be explicit, where possible.

Обзор классов

Thread extends Threaded implements Countable , Traversable , ArrayAccess {
/* Методы */
public void detach ( void )
public integer getCreatorId ( void )
public static Thread getCurrentThread ( void )
public static integer getCurrentThreadId ( void )
public integer getThreadId ( void )
public static mixed globally ( void )
public boolean isJoined ( void )
public boolean isStarted ( void )
public boolean join ( void )
public void kill ( void )
public boolean start ([ integer $options ] )
/* Наследуемые методы */
public array Threaded::chunk ( integer $size , boolean $preserve )
public integer Threaded::count ( void )
public bool Threaded::extend ( string $class )
public Threaded Threaded::from ( Closure $run [, Closure $construct [, array $args ]] )
public array Threaded::getTerminationInfo ( void )
public boolean Threaded::isRunning ( void )
public boolean Threaded::isTerminated ( void )
public boolean Threaded::isWaiting ( void )
public boolean Threaded::lock ( void )
public boolean Threaded::merge ( mixed $from [, bool $overwrite ] )
public boolean Threaded::notify ( void )
public boolean Threaded::pop ( void )
public void Threaded::run ( void )
public mixed Threaded::shift ( void )
public mixed Threaded::synchronized ( Closure $block [, mixed $... ] )
public boolean Threaded::unlock ( void )
public boolean Threaded::wait ([ integer $timeout ] )
}

Содержание

Коментарии

<?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();
}

?>
2014-04-02 02:01:23
http://php5.kiev.ua/manual/ru/class.thread.html
<?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();

?>
2016-03-28 02:11:16
http://php5.kiev.ua/manual/ru/class.thread.html

    Поддержать сайт на родительском проекте КГБ