{"id":285934,"date":"2017-05-04T18:00:03","date_gmt":"2017-05-04T14:00:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=285934"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=285934","title":{"rendered":"\u0412\u0435\u0431 \u0441\u043e\u043a\u0435\u0442\u044b \u0438\u043b\u0438 hello world \u043f\u043e \u043d\u043e\u0432\u043e\u043c\u0443"},"content":{"rendered":"<p>\u042f \u043d\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u042f \u043b\u044e\u0431\u0438\u0442\u044c \u0437\u0430\u044e\u0437\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u0441\u0440\u043e\u043a\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f, \u042f \u0432\u0430\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u044f \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0434\u043d\u044f\u043b \u0447\u0430\u0442\u0438\u043a \u043d\u0430 \u0432\u0435\u0431 \u0441\u043e\u043a\u0435\u0442\u0430\u0445. \u0418 \u043a\u043e\u043d\u043a\u0443\u0440\u0441 \u043e \u0441\u0438\u0441\u044c\u043a\u0430\u0445 \u0432 \u041c\u043e\u0441\u043a\u043e\u0432\u0441\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043a\u0430\u0445.<br \/>   \u0418 \u0442\u0430\u043a \u00abhello world\u00bb \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c ratchet <a href=\"http:\/\/socketo.me\/\">socketo.me<\/a> \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442<br \/>  <a name=\"habracut\"><\/a><br \/>  1. \u0418 \u0442\u0430\u043a \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c composer \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u043f\u0440\u043e\u044d\u043a\u0442\u043e\u043c \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 myProject.<br \/>  2. \u0421\u043e\u0437\u0434\u0430\u0451\u043c composer.json \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c  <\/p>\n<pre><code>{     &quot;autoload&quot;: {         &quot;psr-0&quot;: {             &quot;MyApp&quot;: &quot;src&quot;         }     },     &quot;require&quot;: {         &quot;cboden\/ratchet&quot;: &quot;0.3.*&quot;     } } <\/code><\/pre>\n<p>  \u0418 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>composer install<\/code><br \/>  3. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>src\/MyApp<\/code> \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>Chat<\/code>  <\/p>\n<pre><code class=\"php\">&lt;?php namespace MyApp;  require_once('Db.php');  use Ratchet\\MessageComponentInterface; use Ratchet\\ConnectionInterface; use MyApp\\Db;  class Chat implements MessageComponentInterface {     protected $clients;      public function __construct()     {         $this-&gt;clients = new \\SplObjectStorage;     }      public function onOpen(ConnectionInterface $conn)     {         \/\/ \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0435\u0434\u0435\u043d\u0435\u043d\u0438\u0435         $this-&gt;clients-&gt;attach($conn);     }      \/\/ \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u0441\u043e\u043a\u0435\u0442     public function onMessage(ConnectionInterface $from, $msg)     {           \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u043c \u0442\u0435\u043c \u043a\u0442\u043e \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0435\u043d\u0438\u043b\u0441\u044f         foreach ($this-&gt;clients as $client) {             $client-&gt;send($msg);         }     }      \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u043e\u0435\u0434\u0435\u043d\u0435\u043d\u0438\u044f     public function onClose(ConnectionInterface $conn)     {         $this-&gt;clients-&gt;detach($conn);     }          \/\/ \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a     public function onError(ConnectionInterface $conn, \\Exception $e)     {         $conn-&gt;close();     } }<\/code><\/pre>\n<p>  4. \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>bin<\/code> \u0441\u0435\u0440\u0432\u0435\u0440 <code>server.php<\/code>  <\/p>\n<pre><code class=\"php\"> &lt;?php use Ratchet\\Server\\IoServer; use Ratchet\\Http\\HttpServer; use Ratchet\\WebSocket\\WsServer; use MyApp\\Chat;  require dirname(__DIR__) . '\/vendor\/autoload.php'; $server = IoServer::factory(     new HttpServer( \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c http \u0441\u0435\u0440\u0432\u0435\u0440         new WsServer( \/\/ websocket \u0441\u0435\u0440\u0432\u0435\u0440             new Chat() \/\/ \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439         )     ),     8080,     '127.0.0.1' );  $server-&gt;run(); <\/code><\/pre>\n<p>  5. \u0414\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441 \u0441\u043e\u043a\u0435\u0442\u043e\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 js  <\/p>\n<pre><code class=\"javascript\">var conn = new WebSocket('ws:\/\/127.0.0.1:8080');<\/code><\/pre>\n<p>  \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u0441\u043e\u043a\u0435\u0442\u0430 \u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e \u0432\u0435\u0448\u0430\u0442\u044c \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>onmessage<\/code> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e  <\/p>\n<pre><code class=\"javascript\">conn.onmessage = function(e) {      console.log(e.data); }<\/code><\/pre>\n<p>  \u0432 data \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0442\u0440\u043e\u043a\u0430  <\/p>\n<pre><code class=\"javascript\">conn.send('hello world')<\/code><\/pre>\n<p> \u0442\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440.<br \/>  6. \u0417\u0430\u043f\u0443\u0441\u043a \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0440\u0430:<br \/>   \u2014 \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440<code> php bin\/server.php<\/code><br \/>   \u2014 \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0443 \u0438 \u0433\u043e\u0442\u043e\u0432\u043e<\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u0441\u044b\u043b\u043a\u0438:<br \/>  1. \u0427\u0430\u0442\u0438\u043a \u043d\u0430 \u0441\u043e\u043a\u0435\u0442\u0430\u0445 <a href=\"http:\/\/sidimvprobke.com\/\">sidimvprobke.com<\/a><br \/>  2. git \u0440\u0435\u043f\u0430\u0437\u0438\u0442\u043e\u0440\u0438\u0439 <a href=\"https:\/\/github.com\/lnroma\/sidimvprobke\">github.com\/lnroma\/sidimvprobke<\/a><br \/>  3. \u043a\u043e\u043d\u043a\u0443\u0440\u0441 \u2014 \u043a\u043e\u043d\u043a\u0443\u0440\u0441 \u0441 \u0441\u0438\u0441\u044c\u043a\u0430\u043c\u0438 (\u0442\u0435\u0441\u0442 \u043d\u0430 \u0441\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0432\u0435\u0434\u044c \u0437\u0430\u0432\u0442\u0440\u0430 \u043f\u044f\u0442\u043d\u0438\u0446\u0430)<\/p>\n<p>  \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?<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:\/\/habrahabr.ru\/post\/328016\/\"> https:\/\/habrahabr.ru\/post\/328016\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u042f \u043d\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u042f \u043b\u044e\u0431\u0438\u0442\u044c \u0437\u0430\u044e\u0437\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u0441\u0440\u043e\u043a\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f, \u042f \u0432\u0430\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u044f \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0434\u043d\u044f\u043b \u0447\u0430\u0442\u0438\u043a \u043d\u0430 \u0432\u0435\u0431 \u0441\u043e\u043a\u0435\u0442\u0430\u0445. \u0418 \u043a\u043e\u043d\u043a\u0443\u0440\u0441 \u043e \u0441\u0438\u0441\u044c\u043a\u0430\u0445 \u0432 \u041c\u043e\u0441\u043a\u043e\u0432\u0441\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043a\u0430\u0445.<br \/>   \u0418 \u0442\u0430\u043a \u00abhello world\u00bb \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c ratchet <a href=\"http:\/\/socketo.me\/\">socketo.me<\/a> \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442  <\/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-285934","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285934","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=285934"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285934\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}