public function __construct($nsp) { parent::__construct($nsp); $this->_channelId = rand(1, 10000000) . "-" . (function_exists('posix_getpid') ? posix_getpid() : 1); \Channel\Client::connect(self::$ip, self::$port); \Channel\Client::$onMessage = array($this, 'onChannelMessage'); \Channel\Client::subscribe("socket.io#/#"); Debug::debug('ChannelAdapter __construct'); }
<?php use Workerman\Worker; use Workerman\Lib\Timer; // composer autoload include __DIR__ . '/../vendor/autoload.php'; $channel_server = new Channel\Server(); $worker = new Worker(); $worker->onWorkerStart = function () { Channel\Client::on('test event', function ($event_data) { echo 'test event triggered event_data :'; var_dump($event_data); }); Timer::add(5, function () { Channel\Client::publish('test event', 'some data'); }); }; Worker::runAll();
<?php use Workerman\Worker; use Workerman\Lib\Timer; // composer autoload include __DIR__ . '/../vendor/autoload.php'; $channel_server = new Channel\Server(); $worker = new Worker(); $worker->onWorkerStart = function () { Channel\Client::$onMessage = function ($channel, $data) { var_dump($channel, $data); }; Channel\Client::subscribe('abc'); Timer::add(5, function () { Channel\Client::publish('abc', array('efg')); }); }; Worker::runAll();