PHP Thruway发布变量

时间:2018-02-02 16:37:24

标签: php websocket thruway

我有这个代码。我想要做的是将$ d变量传递给publish事件,有没有办法做到这一点以及如何使用Thruway PHP发布变量数据?

$d='123';
$connection->on('open', function (\Thruway\ClientSession $session) use ($connection) {
    //publish an event
    $session->publish('com.app.deposit', ['Hello, world from PHP!!!'], ['d'=>$d], ["acknowledge" => true])->then(
        function () use ($connection) {
            $connection->close(); //You must close the connection or this will hang
            echo "Publish Acknowledged!\n";
        },
        function ($error) {
            // publish failed
            echo "Publish Error {$error}\n";
        }
    );
  });

 $connection->open();

1 个答案:

答案 0 :(得分:0)

哦,明白了。只需要使用

$connection->on('open', function (\Thruway\ClientSession $session) use ($connection,$d) {