Регистрация Войти
Войти через VK Войти через FB Войти через Google Войти через Яндекс
Войти через VK Войти через FB Войти через Google Войти через Яндекс
Поиск по сайту
The Worker class
(PECL pthreads >= 0.36)
Введение
Worker Threads have a persistent context, as such should be used over Threads in most cases.
Обзор классов
Worker {
/* Методы */
final public boolean chunk ( long $size , boolean $preserve )
final public long getCreatorId ( void )
final public int getStacked ( void )
final public long getThreadId ( void )
final public boolean isShutdown ( void )
final public boolean isWorking ( void )
final public boolean merge ( mixed $from [, mixed $overwrite ] )
final public boolean pop ( void )
abstract public void run ( void )
final public boolean shift ( void )
final public boolean shutdown ( void )
final public int stack ( Stackable $work )
final public boolean start ([ long $options ] )
final public int unstack ([ Stackable $work ] )
}
Содержание
- Worker::chunk — Manipulation
- Worker::getCreatorId — Identification
- Worker::getStacked — Stack Analysis
- Worker::getThreadId — Identification
- Worker::isShutdown — State Detection
- Worker::isWorking — State Detection
- Worker::merge — Manipulation
- Worker::pop — Manipulation
- Worker::run — Execution
- Worker::shift — Manipulation
- Worker::shutdown — Synchronization
- Worker::stack — Stacking
- Worker::start — Execution
- Worker::unstack — Stacking
User Contributed Notes 1 note
0
event2game at gmail dot com ¶1 month ago
class data extends Stackable{
//private $name;
public function __construct($_name) {
//$this->name = $_name;//if you set any variable, workers will get the variable, so do not set any variable
echo __FILE__.'-'.__LINE__.'<br/>'.chr(10);
}
public function run(){
echo __FILE__.'-'.__LINE__.'<br/>'.chr(10);
}
}
class readWorker extends Worker {
public function __construct(&$_data) {
$this->data = $_data;//
}
public function run(){
while(1){
if($arr=$this->data->shift())//receiving datas
{
echo 'Received data:'.print_r($arr,1).chr(10);
}else usleep(50000);
}
}
}
class writeWorker extends Worker {
public function __construct(&$_data) {
$this->data = $_data;//
}
public function run(){
while(1){
$this->data[] = array(time(),rand());//writting datas
usleep(rand(50000, 1000000));
}
}
}
$data = new data('');
$reader = new readWorker($data);
$writer = new writeWorker($data);
$reader->start();
$writer->start();
Описание класса worker, примеры использования класса worker.
Смотрите также:
Описание на ru2.php.net
Описание на php.ru