略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pht\Thread::addClassTask (官方文档)

2021-04-11

pht\Thread::addClassTask

(PECL pht >= 0.0.1)

pht\Thread::addClassTaskClass threading

说明

public pht\Thread::addClassTask ( string $className [, mixed $...ctorArgs ] ) : void

Adds a new class task to a pht\Threads internal task queue.

参数

className

The name of the class to be threaded. This class must implement the pht\Runnable interface.

...ctorArgs

An optional list of arguments for the threaded class' constructor. These arguments will be serialised (since they are being passed to another thread).

返回值

No return value.

范例

Example #1 Adding a new class task to a thread

<?php

use pht\{ThreadRunnable};

class 
Task implements Runnable
{
    private 
$one;

    public function 
__construct(int $one)
    {
        
$this->one $one;
    }

    public function 
run()
    {
        
var_dump($this->one);
    }
}

$thread = new Thread();

$thread->addClassTask(Task::class, 1);

$thread->start();
$thread->join();

以上例程会输出:

int(1)
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/pht-thread.addClassTask.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3