请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

foreach($_POST['http_server']->ports[0]->connections as $fd) { 无效

$data = [

            'type' => intval($_GET['type']),

            'title' => !empty($teams[$_GET['team_id']]['name']) ?$teams[$_GET['team_id']]['name'] : '直播员',

            'logo' => !empty($teams[$_GET['team_id']]['logo']) ?$teams[$_GET['team_id']]['logo'] : '',

            'content' => !empty($_GET['content']) ? $_GET['content'] : '',

            'image' => !empty($_GET['image']) ? $_GET['image'] : '',

        ];



        foreach($_POST['http_server']->ports[0]->connections as $fd) {

            $_POST['http_server']->push($fd, json_encode($data));

        }



        return Util::show(config('code.success'), 'ok');


无返回,改成ports[1],会正常return,是不支持ports[0]吗,还是我写的有问题

正在回答 回答被采纳积分+3

3回答

提问者 Mini_xing 2018-05-25 14:38:20


Swoole\WebSocket\Server Object
(
    [onConnect] => 
    [onReceive] => 
    [onClose] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onClose
        )

    [onPacket] => 
    [onBufferFull] => 
    [onBufferEmpty] => 
    [onStart] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onStart
        )

    [onShutdown] => 
    [onWorkerStart] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onWorkerStart
        )

    [onWorkerStop] => 
    [onWorkerExit] => 
    [onWorkerError] => 
    [onTask] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onTask
        )

    [onFinish] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onFinish
        )

    [onManagerStart] => 
    [onManagerStop] => 
    [onPipeMessage] => 
    [connections] => Swoole\Connection\Iterator Object
        (
        )

    [host] => 0.0.0.0
    [port] => 8811
    [type] => 1
    [mode] => 3
    [ports] => Array
        (
            [0] => Swoole\Server\Port Object
                (
                    [onConnect] => 
                    [onReceive] => 
                    [onClose] => Array
                        (
                            [0] => Ws Object
                                (
                                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                                )

                            [1] => onClose
                        )

                    [onPacket] => 
                    [onBufferFull] => 
                    [onBufferEmpty] => 
                    [onRequest] => 
                    [onHandShake] => 
                    [onMessage] => 
                    [onOpen] => 
                    [host] => 0.0.0.0
                    [port] => 8811
                    [type] => 1
                    [sock] => 3
                    [setting] => Array
                        (
                            [enable_static_handler] => 1
                            [document_root] => /alidata/www/swoole/imooc/thinkphp/public/static
                            [worker_num] => 4
                            [task_worker_num] => 4
                        )

                    [connections] => Swoole\Connection\Iterator Object
                        (
                        )

                )

            [1] => Swoole\Server\Port Object
                (
                    [onConnect] => 
                    [onReceive] => 
                    [onClose] => 
                    [onPacket] => 
                    [onBufferFull] => 
                    [onBufferEmpty] => 
                    [onRequest] => 
                    [onHandShake] => 
                    [onMessage] => 
                    [onOpen] => 
                    [host] => 0.0.0.0
                    [port] => 8812
                    [type] => 1
                    [sock] => 4
                    [setting] => Array
                        (
                            [enable_static_handler] => 1
                            [document_root] => /alidata/www/swoole/imooc/thinkphp/public/static
                            [worker_num] => 4
                            [task_worker_num] => 4
                            [open_http_protocol] => 1
                            [open_mqtt_protocol] => 
                            [open_eof_check] => 
                            [open_length_check] => 
                            [open_websocket_protocol] => 1
                        )

                    [connections] => Swoole\Connection\Iterator Object
                        (
                        )

                )

        )

    [master_pid] => 18619
    [manager_pid] => 18620
    [worker_id] => 1
    [taskworker] => 
    [worker_pid] => 10118
    [onRequest] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onRequest
        )

    [onHandshake] => 
    [setting] => Array
        (
            [enable_static_handler] => 1
            [document_root] => /alidata/www/swoole/imooc/thinkphp/public/static
            [worker_num] => 4
            [task_worker_num] => 4
            [open_http_protocol] => 1
            [open_mqtt_protocol] => 
            [open_eof_check] => 
            [open_length_check] => 
            [open_websocket_protocol] => 1
        )

    [onOpen] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onOpen
        )

    [onMessage] => Array
        (
            [0] => Ws Object
                (
                    [ws] => Swoole\WebSocket\Server Object
 *RECURSION*
                )

            [1] => onMessage
        )

)
string(98) "Swoole\WebSocket\Server::push(): the connected client of connection[62] is not a websocket client."
{"status":1,"message":"ok","data":[]}


0 回复 有任何疑惑可以回复我~
singwa 2018-05-24 23:49:52

您好 ,您先 打印 

$_POST['http_server']

 看看 你那边返回什么内容

0 回复 有任何疑惑可以回复我~
  • 提问者 Mini_xing #1
    try{
    	print_r($_POST['http_server']);
    	 foreach($_POST['http_server']->ports[0]->connections as $fd) {
    		 $_POST['http_server']->push($fd, json_encode($data));
    	 }
    
     }catch (Exception $e){
    	 var_dump($e->getMessage());
     }
    
     return Util::show(config('code.success'), 'ok');
    
    我try catch 了一下,上面是打印的内容
    回复 有任何疑惑可以回复我~ 2018-05-25 14:39:39
提问者 Mini_xing 2018-05-23 11:47:36

错误信息  Swoole\WebSocket\Server::push(): the connected client of connection[2] is not a websocket client

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信