略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Threaded::from

2024-07-27

Threaded::from

(PECL pthreads >= 2.0.9)

Threaded::fromCreation

Warning

This method has been removed in pthreads v3. With the introduction of anonymous classes in PHP 7, these can now be used instead.

说明

public Threaded::from ( Closure $run [, Closure $construct [, array $args ]] ) : Threaded

Creates an anonymous Threaded object from closures

参数

run

The closure to use for ::run

construct

The constructor to use for anonymous object

args

The arguments to pass to constructor

返回值

A new anonymous Threaded object

范例

Example #1 Thread safe objects from closures

<?php
$pool 
= new Pool(4);
$pool->submit(Collectable::from(function(){
    echo 
"Hello World";
    
$this->setGarbage();
}));
/* ... */
$pool->shutdown();
?>

以上例程会输出:

Hello World
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/threaded.from.php

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