{"id":291299,"date":"2018-10-24T16:40:03","date_gmt":"2018-10-24T12:40:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=291299"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=291299","title":{"rendered":"\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 WEB \u0432 2018. \u041f\u0438\u0448\u0435\u043c \u0447\u0430\u0442 \u043d\u0430 Websocket \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Swoole"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8p\/gc\/di\/8pgcdiztceoyeqy2os69qvw8rmq.png\"\/><\/p>\n<p>  \u0422\u0435\u043c\u0430 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/WebSocket\">Websocket`\u043e\u0432<\/a> \u0443\u0436\u0435 \u043d\u0435 \u0440\u0430\u0437 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u043b\u0430\u0441\u044c \u043d\u0430 \u0425\u0430\u0431\u0440\u0435, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 PHP. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0432\u044b\u0445\u043e\u0434\u0430 <a href=\"https:\/\/habr.com\/post\/331462\/\">\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u0441 \u043e\u0431\u0437\u043e\u0440\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439 \u043f\u0440\u043e\u0448\u043b\u043e \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u0433\u043e\u0434\u0430, \u0430 \u043c\u0438\u0440\u0443 PHP <a href=\"https:\/\/tsh.io\/blog\/swoole-is-it-node-in-php-or-am-i-wrong\/?utm_source=twitter&amp;utm_medium=social&amp;utm_campaign=php&amp;utm_content=fanpage\">\u0435\u0441\u0442\u044c \u0447\u0435\u043c<\/a> \u043f\u043e\u0445\u0432\u0430\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 <a href=\"https:\/\/www.swoole.co.uk\">Swoole<\/a> \u2014 \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 Open Source \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f PHP, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0421\u0438, \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0432 \u0432\u0438\u0434\u0435 pecl-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0435\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435(\u0447\u0430\u0442) \u043c\u043e\u0436\u043d\u043e: <a href=\"http:\/\/62.109.21.96\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<br \/>  <a href=\"https:\/\/github.com\/EvgeniiR\/ws-chat\">\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0430 github<\/a>.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443 Swoole?<\/h2>\n<p>  \u041d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043d\u0430\u0439\u0434\u0443\u0442\u0441\u044f \u043b\u044e\u0434\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043f\u0440\u043e\u0442\u0438\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f PHP \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0446\u0435\u043b\u0435\u0439, \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 PHP \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0438\u0433\u0440\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\u041d\u0435\u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u043e\u043e\u043f\u0430\u0440\u043a \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/li>\n<li>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0436\u0435 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b(\u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 PHP).<\/li>\n<li>\u0414\u043b\u044f PHP-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0435\u0449\u0451 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 <abbr title=\"\u042f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\">\u042f\u041f<\/abbr>.<\/li>\n<\/ul>\n<p>  \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0434\u0430\u0436\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044f \u0441 node.js\/go\/erlang \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u044f\u0437\u044b\u043a\u0430\u043c\u0438, \u043d\u0430\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0449\u0438\u043c\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, Swoole \u2014 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0421\u0438 \u0438 \u043e\u0431\u044a\u0435\u0434\u0435\u043d\u0438\u0432\u0448\u0438\u0439 \u0432 \u0441\u0435\u0431\u0435 \u043d\u0438\u0437\u043a\u0438\u0439 \u043f\u043e\u0440\u043e\u0433 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u043c\u043e\u0449\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u043c.<\/p>\n<p>  <b>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430:<\/b><\/p>\n<ul>\n<li> \u0421\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u0430\u044f, \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/li>\n<li> \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 TCP \/ UDP \/ HTTP \/ Websocket \/ HTTP2 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0435\/\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0435 API<\/li>\n<li> \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 IPv4 \/ IPv6 \/ Unixsocket \/ TCP\/ UDP \u0438 SSL \/ TLS <\/li>\n<li> \u0411\u044b\u0441\u0442\u0440\u0430\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \/ \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/li>\n<li> \u0412\u044b\u0441\u043e\u043a\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u044c, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0434\u043e 1 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439<\/li>\n<li>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u0441 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434<\/li>\n<li> <a href=\"https:\/\/github.com\/swoole\/swoole-src\">Open source<\/a><\/li>\n<li> <a href=\"https:\/\/www.swoole.co.uk\/coroutine\">\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c(Coroutines)<\/a><\/li>\n<\/ul>\n<p>  <b>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f: <\/b><\/p>\n<ul>\n<li> \u041c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/li>\n<li> \u0418\u0433\u0440\u043e\u0432\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/li>\n<li> \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0432\u0435\u0449\u0435\u0439<\/li>\n<li> \u0416\u0438\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/li>\n<li> WEB API<\/li>\n<li> \u041b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442\/\u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\/\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <\/li>\n<\/ul>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/www.swoole.co.uk\/\">\u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0441\u0430\u0439\u0442\u0430<\/a>. \u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0432\u0441\u0451\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<h2>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e<\/h2>\n<p>  \u041d\u0438\u0436\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e Websocket \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u043b\u044f \u043e\u043d\u043b\u0430\u0439\u043d-\u0447\u0430\u0442\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c: \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043a\u043b\u0430\u0441\u0441\u0430\u0445 <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-websocket-server\">swoole_websocket_server<\/a> \u0438 <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-server-doc\">swoole_server<\/a> (\u0412\u0442\u043e\u0440\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e).<br \/>  <a href=\"https:\/\/github.com\/EvgeniiR\/ws-chat\">\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u0447\u0430\u0442\u0430.<\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\"><code>Linux users<\/p>\n<p>  #!\/bin\/bash<br \/>  pecl install swoole<\/p>\n<p>  Mac users<\/p>\n<p>  # get a list of avaiable packages<br \/>  brew install swoole <br \/>  #!\/bin\/bash<br \/>  brew install homebrew\/php\/php71-swoole<br \/>  <\/code>  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u043a\u043e\u043c\u043f\u043b\u0438\u0442\u0430 \u0432 IDE \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/wudi\/swoole-ide-helper\">ide-helper<\/a><\/p>\n<p>  <b>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d Websocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430:<\/b><\/p>\n<pre><code class=\"php\">&lt;?php $server = new swoole_websocket_server(&quot;127.0.0.1&quot;, 9502);  $server-&gt;on('open', function($server, $req) {     echo &quot;connection open: {$req-&gt;fd}\\n&quot;; });  $server-&gt;on('message', function($server, $frame) {     echo &quot;received message: {$frame-&gt;data}\\n&quot;;     $server-&gt;push($frame-&gt;fd, json_encode([&quot;hello&quot;, &quot;world&quot;])); });  $server-&gt;on('close', function($server, $fd) {     echo &quot;connection close: {$fd}\\n&quot;; });  $server-&gt;start(); <\/code><\/pre>\n<p>  $fd \u2014 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<br \/>  \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f: <\/p>\n<pre><code class=\"php\">$server-&gt;connections;<\/code><\/pre>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 $frame \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e onMessage:<\/p>\n<pre><code>Swoole\\WebSocket\\Frame Object (        [fd] =&gt; 20     [data] =&gt; {&quot;type&quot;:&quot;login&quot;,&quot;username&quot;:&quot;new user&quot;}     [opcode] =&gt; 1     [finish] =&gt; 1 ) <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <\/p>\n<pre><code class=\"php\">Server::push($fd, $data, $opcode=null, $finish=null)<\/code><\/pre>\n<p>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0444\u0440\u0435\u0439\u043c\u044b \u0438 opcodes \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u2014 \u043d\u0430 <a href=\"https:\/\/learn.javascript.ru\/websockets#%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D1%82-%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85\">learn.javascript<\/a>. \u0420\u0430\u0437\u0434\u0435\u043b \u00ab\u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445\u00bb<\/p>\n<p>  \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b Websocket \u2014 <a href=\"https:\/\/tools.ietf.org\/html\/rfc6455\">RFC<\/a><\/p>\n<p>  <b>\u0410 \u043a\u0430\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440?<\/b><br \/>  Swoole \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-async-mysql-client\">MySQL<\/a>, <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-async-redis-client\">Redis<\/a>, <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-async-io\">\u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0432\u0432\u043e\u0434-\u0432\u044b\u0432\u043e\u0434<\/a><\/p>\n<p>  \u0410 \u0442\u0430\u043a\u0436\u0435 <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-buffer\">swoole_buffer<\/a>, <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-channel\">swoole_channel<\/a> \u0438 <a href=\"https:\/\/www.swoole.co.uk\/docs\/modules\/swoole-table\">swoole_table<\/a><br \/>  \u0414\u0443\u043c\u0430\u044e \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043c\u0451\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u044f \u0432\u044b\u0431\u0440\u0430\u043b swoole_table. \u0421\u0430\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 MySQL. <\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u043c\u0451\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"php\">         $users_table = new swoole_table(131072); $users_table-&gt;column('id', swoole_table::TYPE_INT, 5); $users_table-&gt;column('username', swoole_table::TYPE_STRING, 64); $users_table-&gt;create(); <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">$count = count($messages_table);  $dateTime = time(); $row = ['username' =&gt; $username, 'message' =&gt; $data-&gt;message, 'date_time' =&gt; $dateTime]; $messages_table-&gt;set($count, $row); <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 MySQL \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043a\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u0438\u0437 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0447\u0435\u0440\u0435\u0437 PDO<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">\/**      * @return Message[]      *\/     public function getAll()     {         $stmt = $this-&gt;pdo-&gt;query('SELECT * from messages');         $messages = [];         foreach ($stmt-&gt;fetchAll() as $row) {             $messages[] = new Message( $row['username'], $row['message'], new \\DateTime($row['date_time']) );         }         return $messages;     }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  Websocket \u0441\u0435\u0440\u0432\u0435\u0440 \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u0438 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">public function __construct()     {         $this-&gt;ws = new swoole_websocket_server('0.0.0.0', 9502);          $this-&gt;ws-&gt;on('open', function ($ws, $request) {             $this-&gt;onConnection($request);         });         $this-&gt;ws-&gt;on('message', function ($ws, $frame) {             $this-&gt;onMessage($frame);         });         $this-&gt;ws-&gt;on('close', function ($ws, $id) {             $this-&gt;onClose($id);         });          $this-&gt;ws-&gt;on('workerStart', function (swoole_websocket_server $ws) {             $this-&gt;onWorkerStart($ws);         });          $this-&gt;ws-&gt;start();     }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <b>\u0412\u043e\u0437\u043d\u0438\u043a\u0448\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/b><\/p>\n<ol>\n<li> \u0423 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043a \u0447\u0430\u0442\u0443 \u043e\u0431\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 60 \u0441\u0435\u043a\u0443\u043d\u0434 \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0431\u043c\u0435\u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438(\u0442.\u0435. \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b)<\/li>\n<li> \u0412\u0435\u0431\u0441\u0435\u0440\u0432\u0435\u0440 \u0442\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 MySQL \u0435\u0441\u043b\u0438 \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/li>\n<\/ol>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<p>  \u0412 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f \u043d\u0443\u0436\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00ab\u043f\u0438\u043d\u0433\u00bb, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0435 n \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0438\u043d\u0433\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438 \u0431\u0430\u0437\u0443 MySQL \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u00abworkerStart\u00bb. \u041c\u044b \u0443\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u0443\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 $this-&gt;onWorkerStart:<br \/>  \u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b Websocket \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WebSockets_API\/Writing_WebSocket_servers#Pings_and_Pongs_The_Heartbeat_of_WebSockets\">ping-pong<\/a> \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438. \u041d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 Swoole.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">onWorkerStart<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">private function onWorkerStart(swoole_websocket_server $ws)     {         $this-&gt;messagesRepository = new MessagesRepository();          $ws-&gt;tick(self::PING_DELAY_MS, function () use ($ws) {             foreach ($ws-&gt;connections as $id) {                 $ws-&gt;push($id, 'ping', WEBSOCKET_OPCODE_PING);             }         });     }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0438\u043d\u0433\u0430 MySQL \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a\u0430\u0436\u0434\u044b\u0435 N \u0441\u0435\u043a\u0443\u043d\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f swoole\\Timer:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">DatabaseHelper<\/b><\/p>\n<div class=\"spoiler_text\">\u0421\u0430\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 initPdo \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d:<\/p>\n<pre><code class=\"php\">    \/**      * Init new Connection, and ping DB timer function      *\/     private static function initPdo()     {         if (self::$timerId === null || (!Timer::exists(self::$timerId))) {             self::$timerId = Timer::tick(self::MySQL_PING_INTERVAL, function () {                 self::ping();             });         }          self::$pdo = new PDO(self::DSN, DBConfig::USER, DBConfig::PASSWORD, self::OPT);     }      \/**      * Ping database to maintain the connection      *\/     private static function ping()     {         try {             self::$pdo-&gt;query('SELECT 1');         } catch (PDOException $e) {             self::initPdo();         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>   \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439(\u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e CRUD), \u0430 \u0434\u0430\u043b\u0435\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0440 \u0434\u043b\u044f \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0439.<\/p>\n<p>  \u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u044f \u043f\u0440\u0438\u0432\u0451\u043b \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u043a \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u0442\u0438\u043b\u044e, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430:<\/p>\n<p>   \u2014 \u0412\u0445\u043e\u0434 \u043f\u043e \u0438\u043c\u0435\u043d\u0438;<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">&#8212; \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0447\u0442\u043e \u0438\u043c\u044f \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u043e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">\/**      * @param string $username      * @return bool      *\/     private function isUsernameCurrentlyTaken(string $username) {         foreach ($this-&gt;usersRepository-&gt;getByIds($this-&gt;ws-&gt;connection_list()) as $user) {             if ($user-&gt;getUsername() == $username) {                 return true;             }         }         return false;     }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">&#8212; \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0441\u043f\u0430\u043c\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  namespace App\\Helpers;  use Swoole\\Channel;  class RequestLimiter {     \/**      * @var Channel      *\/     private $userIds;      const MAX_RECORDS_COUNT = 10;      const MAX_REQUESTS_BY_USER = 4;      public function __construct() {         $this-&gt;userIds = new Channel(1024 * 64);     }      \/**      * Check if there are too many requests from user      *  and make a record of request from that user      *      * @param int $userId      * @return bool      *\/     public function checkIsRequestAllowed(int $userId) {         $requestsCount = $this-&gt;getRequestsCountByUser($userId);         $this-&gt;addRecord($userId);         if ($requestsCount &gt;= self::MAX_REQUESTS_BY_USER) return false;         return true;     }      \/**      * @param int $userId      * @return int      *\/     private function getRequestsCountByUser(int $userId) {         $channelRecordsCount = $this-&gt;userIds-&gt;stats()['queue_num'];         $requestsCount = 0;          for ($i = 0; $i &lt; $channelRecordsCount; $i++) {             $userIdFromChannel = $this-&gt;userIds-&gt;pop();             $this-&gt;userIds-&gt;push($userIdFromChannel);             if ($userIdFromChannel === $userId) {                 $requestsCount++;             }         }          return $requestsCount;     }      \/**      * @param int $userId      *\/     private function addRecord(int $userId) {         $recordsCount = $this-&gt;userIds-&gt;stats()['queue_num'];          if ($recordsCount &gt;= self::MAX_RECORDS_COUNT) {             $this-&gt;userIds-&gt;pop();         }          $this-&gt;userIds-&gt;push($userId);     } }<\/code><\/pre>\n<p>  P.S.: \u0414\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0434\u0451\u0442 \u043f\u043e connection id. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 IP \u0430\u0434\u0440\u0435\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  \u0415\u0449\u0451 \u044f \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d \u0447\u0442\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043b \u0438\u043c\u0435\u043d\u043d\u043e swoole_channel. \u0414\u0443\u043c\u0430\u044e \u043f\u043e\u0437\u0436\u0435 \u043f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442.  <\/div>\n<\/div>\n<p>   \u2014 \u041f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0443\u044e \u0437\u0430\u0449\u0438\u0442\u0443 \u043e\u0442 XSS \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <a href=\"https:\/\/packagist.org\/packages\/ezyang\/htmlpurifier\">ezyang\/htmlpurifier<\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">&#8212; \u041f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u043f\u0430\u043c-\u0444\u0438\u043b\u044c\u0442\u0440<\/b><\/p>\n<div class=\"spoiler_text\">\u0421 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Helpers;  class SpamFilter {     \/**      * @var string[] errors      *\/     private $errors = [];      \/**      * @param string $text      * @return bool      *\/     public function checkIsMessageTextCorrect(string $text) {         $isCorrect = true;         if (empty(trim($text))) {             $this-&gt;errors[] = 'Empty message text';             $isCorrect = false;         }         return $isCorrect;     }      \/**      * @return string[] errors      *\/     public function getErrors(): array {         return $this-&gt;errors;     } }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  Frontend \u0443 \u0447\u0430\u0442\u0430 \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u044b\u0440\u043e\u0439, \u0442.\u043a. \u043c\u0435\u043d\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0435\u0442 backend, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0435.<\/p>\n<h2>\u0413\u0434\u0435 \u0431\u0440\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0443\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435?<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/www.swoole.co.uk\">\u0410\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0430\u0439\u0442<\/a> \u2014 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438, \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/li>\n<li><a href=\"https:\/\/twitter.com\/php_swoole\">Twitter<\/a> \u2014 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438, \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438, \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438<\/li>\n<li><a href=\"https:\/\/github.com\/swoole\/swoole-src\/issues\">Issue tracker(Github)<\/a> \u2014 \u0431\u0430\u0433\u0438, \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430. \u041e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 \u043e\u0447\u0435\u043d\u044c \u0448\u0443\u0441\u0442\u0440\u043e(\u043d\u0430 \u043c\u043e\u044e issue \u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0438\u043b\u0438 \u0437\u0430 \u043f\u0430\u0440\u0443 \u0447\u0430\u0441\u043e\u0432, \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 pingloop). <\/li>\n<li><a href=\"https:\/\/github.com\/swoole\/swoole-src\/issues?q=is%3Aissue+is%3Aclosed\">\u0417\u0430\u043a\u0440\u044b\u0442\u044b\u0435 issues<\/a> \u2014 \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0432\u0435\u0442\u0443\u044e. \u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0431\u0430\u0437\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u043e\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u0444\u0440\u0435\u043c\u0432\u043e\u0440\u043a\u0430.<\/li>\n<li><a href=\"https:\/\/github.com\/swoole\/swoole-src\/tree\/master\/tests\">\u0422\u0435\u0441\u0442\u044b, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438<\/a> \u2014 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 PHP, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/li>\n<li><a href=\"https:\/\/wiki.swoole.com\/wiki\/page\/p-async.html\"> \u041a\u0438\u0442\u0430\u0439\u0441\u043a\u0430\u044f wiki \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430<\/a> \u2014 \u0432\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0447\u0442\u043e \u0438 \u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0439, \u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (\u0433\u0443\u0433\u043b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a \u0432 \u043f\u043e\u043c\u043e\u0449\u044c).<\/li>\n<\/ul>\n<p>  <a href=\"https:\/\/rawgit.com\/tchiotludo\/swoole-ide-helper\/english\/docs\/index.html\">API documentation<\/a> \u2014 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0432 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0432\u0438\u0434\u0435. <\/p>\n<h3>\u0420\u0435\u0437\u044e\u043c\u0435<\/h3>\n<p>  \u041c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e Swoole \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434, \u0432\u044b\u0448\u0435\u043b \u0438\u0437 \u0441\u0442\u0430\u0434\u0438\u0438 \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u00ab\u0441\u044b\u0440\u044b\u043c\u00bb, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e node.js\/go \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u0432.<\/p>\n<p>  \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u0442\u0435\u043c\u0435 \u0438 \u043e\u0442\u0437\u044b\u0432\u044b \u043e\u0442 \u0442\u0435\u0445 \u043a\u0442\u043e \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u044b\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Swoole<\/p>\n<p>  \u041f\u043e\u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c \u0447\u0430\u0442\u0438\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e <a href=\"http:\/\/62.109.21.96\/\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a><br \/>  \u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 <a href=\"https:\/\/github.com\/EvgeniiR\/ws-chat\">Github<\/a>.<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/427589\/\"> https:\/\/habr.com\/post\/427589\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8p\/gc\/di\/8pgcdiztceoyeqy2os69qvw8rmq.png\"\/><\/p>\n<p>  \u0422\u0435\u043c\u0430 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/WebSocket\">Websocket`\u043e\u0432<\/a> \u0443\u0436\u0435 \u043d\u0435 \u0440\u0430\u0437 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u043b\u0430\u0441\u044c \u043d\u0430 \u0425\u0430\u0431\u0440\u0435, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 PHP. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0432\u044b\u0445\u043e\u0434\u0430 <a href=\"https:\/\/habr.com\/post\/331462\/\">\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u0441 \u043e\u0431\u0437\u043e\u0440\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439 \u043f\u0440\u043e\u0448\u043b\u043e \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u0433\u043e\u0434\u0430, \u0430 \u043c\u0438\u0440\u0443 PHP <a href=\"https:\/\/tsh.io\/blog\/swoole-is-it-node-in-php-or-am-i-wrong\/?utm_source=twitter&amp;utm_medium=social&amp;utm_campaign=php&amp;utm_content=fanpage\">\u0435\u0441\u0442\u044c \u0447\u0435\u043c<\/a> \u043f\u043e\u0445\u0432\u0430\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 <a href=\"https:\/\/www.swoole.co.uk\">Swoole<\/a> \u2014 \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 Open Source \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f PHP, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0421\u0438, \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0432 \u0432\u0438\u0434\u0435 pecl-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0435\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435(\u0447\u0430\u0442) \u043c\u043e\u0436\u043d\u043e: <a href=\"http:\/\/62.109.21.96\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<br \/>  <a href=\"https:\/\/github.com\/EvgeniiR\/ws-chat\">\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0430 github<\/a>.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-291299","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291299"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291299\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}