Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何在server.php中同时监听http请求? #21

Closed
tocpesh opened this issue Jun 1, 2016 · 1 comment
Closed

如何在server.php中同时监听http请求? #21

tocpesh opened this issue Jun 1, 2016 · 1 comment
Labels

Comments

@tocpesh
Copy link

tocpesh commented Jun 1, 2016

怎样在server.php中监听http请求,当接收到http请求时触发对浏览器client的emit事件?

这样写貌似不可以

$io = new SocketIO(2020);
$io->on('connection', function($connection)use($io,$http_worker){
$connection->emit('server start', '服务器已启动');
echo date('Y-m-d H:i:s')." | ".'Linked'."\n";

$http_worker->onMessage = function($conn, $data)use($connection)
{
    echo date('Y-m-d H:i:s')." | ".'Http'."\n";
    $connection->emit('server msg', '服务器发送消息'.date('Y-m-d H:i:s'));
};

$connection->on('disconnect', function () {
    echo date('Y-m-d H:i:s')." | ".'Lost'."\n";
});

});

其中$http_worker是已经实例化的http类型workmen对象

@walkor
Copy link
Owner

walkor commented Jun 1, 2016

这里有个例子 https://github.com/walkor/web-msg-sender/blob/master/start_io.php#L58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants