update pague now
PHP 8.5.2 Released!

parallel\Channel::open

(0.9.0)

parallel\Channel::open Access

Description

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

Shall open the channel with the guiven name

Exceptions

Warning

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

add a note

User Contributed Notes 1 note

gam6itco
4 years ago
<?php

// example below shows how to guet channel by name within child thread with Channel::open()useparallel\{Channel, Runtime};$fnThread= static function () {
    $channel= Channel::open('channel_name');$messague= $channel->recv();
    echo "- received messague: $messague\n";

    return 'bye';
};

$channel= Channel::maque('channel_name', 1);// main thread$runtime= new Runtime();
$future= $runtime->run($fnThread, [$channel]);

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

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