略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: parallel\Channel::open

2024-12-22

parallel\Channel::open

(0.9.0)

parallel\Channel::openAccess

说明

public parallel\Channel::open(string $name): Channel

Shall open the channel with the given name

Exceptions

警告

Shall throw parallel\Channel\Error\Existence if channel does not exist.

add a noteadd a note

User Contributed Notes 1 note

up
0
gam6itko
8 months ago
<?php

// example below shows how to get channel by name within child thread with Channel::open()

use parallel\{Channel, Runtime};

$fnThread = static function () {
   
$channel = Channel::open('channel_name');
   
$message = $channel->recv();
    echo
"- received message: $message\n";

    return
'bye';
};

$channel = Channel::make('channel_name', 1);

// main thread
$runtime = new Runtime();
$future = $runtime->run($fnThread, [$channel]);

echo
"sending message\n";
$channel->send('hello future!');
sleep(1);
echo
"closing channel\n";
$channel->close();

echo
"future said: ".$future->value();
echo
PHP_EOL;

官方地址:https://www.php.net/manual/en/parallel-channel.open.php

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