请稍等 ...
×

采纳答案成功!

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

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号