Home >Backend Development >PHP Tutorial >The problem that the onclose and onconnect interfaces are not called in the swoole extension of PHP, swooleonclose_PHP tutorial
I encountered a problem when using the swoole extension to write an online chat example, and I checked a lot The information is now recorded here.
By looking at the interface document of swoole_server, there is a clear comment in the callback registration interface on:
* swoole_server->on & swoole_http_server->on are the same except swoole_http_server : * - not accepting onConnect/onReceive callback accept events onRequest
swoole_http_server and swoole_server are roughly the same, but the connect and receive interfaces are not called in swoole_http_server, and the request interface is called accordingly.
In the small example of chatting, swoole_websocket_server is used. Through testing, the receive interface in swoole_websocket_server is not called, but as a long connection service, in the worker
The callbacks in close and connect are still necessary. For example, online broadcast notifications and offline broadcast notifications require callbacks to these two corresponding interfaces to implement them well. So the official definitely supports the callback.
The problem was finally found through a swoole version update announcement.
swoole-1.7.16 version has been released, BUG fixed version:
Add swoole_server->tick and swoole_timer_tick functions
Add http server support for gzip compression
Add swoole_table->incr/decr atomic increment/decrement method
Add open_eof_split configuration, use EOF Detection can support automatic subcontracting
Add server statistical items request_count and worker_request_count
Add server connection iterator, you can use foreach to traverse all connections of the server
Add http server request query_string
Add http server multipart -Support for form and uploaded files
Fix the BUG of onReceive data merging failure
Fix the BUG of conflict between swoole_server->addtimer and tick timer
Fix the problem of Accept not setting blocking under low version Linux
Fix the problem of Repeated Log Printing when Accept fails and returns Too Many Connection
Fix the problem of invalid task_max_request parameter
Fix the problem of invalid waitall parameter of swoole_client
Fix the bug of infinite loop in swoole_table
WebSocket server onOpen callback function No. The two parameters are adjusted from $fd to $request object
Http server allows sending empty body response
Disable swoole_websocket_server->send method
BASE mode supports sending data to any FD
Set dispatch_mode = 1, 3 and then close the onClose/onConnect event callback
Allow setting of non-system reserved signals in the Worker process
Remove the underlying dependence of swoole on object resource attributes and read them directly Pointers, improve performance
Solve the problem that the heartbeat thread cannot forcefully kill legacy connections
Optimize the dispatch_mode=3 mode to improve the efficiency of task distribution
It is a problem of worker allocation mode. In preemption mode and polling mode, these two callback interfaces are no longer called. In fixed mode, each client's data packet will be processed by a fixed worker process, so that some private information belonging to this client can be stored in the worker process, and some frequently read and written data can be cached, which is similar to the process dictionary in Erlang. operate. In this way, the client needs to do some cleaning operations when it goes offline. Online initialization operation. So this model is very meaningful and necessary. Fixed mode is suitable for handling situations where each client's logic is relatively uniform.