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接收get参数 #6

Closed
lly835 opened this issue Feb 14, 2016 · 9 comments
Closed

如何让server.php接收get参数 #6

lly835 opened this issue Feb 14, 2016 · 9 comments

Comments

@lly835
Copy link

lly835 commented Feb 14, 2016

我想让server.php接收get参数,然后传给客户端,不知道如何操作。下面这种方式是不行的

use Workerman\Worker;
use PHPSocketIO\SocketIO;

// composer autoload
include __DIR__ . '/vendor/autoload.php';

$io = new SocketIO(2021);

// 当有客户端连接时
$io->on('connection', function($connection)use($io){
    // 定义chat message事件回调函数
//    $connection->on('chat message', function($msg)use($io){
        // 触发所有客户端定义的chat message from server事件
        $io->emit('chat message', $_GET['key']);
//    });
});

Worker::runAll();

image

@walkor
Copy link
Owner

walkor commented Feb 16, 2016

server.php文件不是用浏览器访问的。是在命令行里面运行的。
php server.php start debug方式运行 或者 php server.php start -d守护进程方式运行

客户端给服务端发送数时据客户端直接emit即可,不用get传递。

phpsocket.io使用方法参考docs目录的手册 https://github.com/walkor/phpsocket.io/tree/master/docs/zh

@lly835
Copy link
Author

lly835 commented Feb 18, 2016

我想说,其实是有这种需求的。。。

@walkor
Copy link
Owner

walkor commented Feb 18, 2016

PHPSocket.IO里面可以这样获得get参数

$io->on('connection', function($socket)use($io){
        $io->emit('chat message', $socket->request->_query['key']);
});

@lly835
Copy link
Author

lly835 commented Mar 8, 2016

还是不行
image

我希望访问浏览器,将key的值推送给客户端

@walkor
Copy link
Owner

walkor commented Mar 8, 2016

上面说过了,server.php 不是用浏览器来访问的,是命令行运行的

@lly835
Copy link
Author

lly835 commented Mar 8, 2016

那就是说,不能实现我说的那种需求?

@walkor
Copy link
Owner

walkor commented Mar 8, 2016

获取get参数能实现,上面已经给了方法。

@lly835
Copy link
Author

lly835 commented Mar 8, 2016

我想在server.php里获取 又想通过浏览器访问server.php

@walkor
Copy link
Owner

walkor commented Mar 8, 2016

你不了解phpsocket.io的运行机制,我是没办法和你沟通的。
你就当phpsocket.io无法满足你的需求吧。

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

No branches or pull requests

3 participants
@lly835 @walkor and others