{"action":"created","issue":{"url":"https://api.github.com/repos/ratchetphp/Pawl/issues/33","repository_url":"https://api.github.com/repos/ratchetphp/Pawl","labels_url":"https://api.github.com/repos/ratchetphp/Pawl/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/ratchetphp/Pawl/issues/33/comments","events_url":"https://api.github.com/repos/ratchetphp/Pawl/issues/33/events","html_url":"https://github.com/ratchetphp/Pawl/issues/33","id":160844493,"number":33,"title":"Keep socket connection open , and send push messages from other classes","user":{"login":"harveyslash","id":7107410,"avatar_url":"https://avatars.githubusercontent.com/u/7107410?v=3","gravatar_id":"","url":"https://api.github.com/users/harveyslash","html_url":"https://github.com/harveyslash","followers_url":"https://api.github.com/users/harveyslash/followers","following_url":"https://api.github.com/users/harveyslash/following{/other_user}","gists_url":"https://api.github.com/users/harveyslash/gists{/gist_id}","starred_url":"https://api.github.com/users/harveyslash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harveyslash/subscriptions","organizations_url":"https://api.github.com/users/harveyslash/orgs","repos_url":"https://api.github.com/users/harveyslash/repos","events_url":"https://api.github.com/users/harveyslash/events{/privacy}","received_events_url":"https://api.github.com/users/harveyslash/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-17T09:10:46Z","updated_at":"2017-01-01T18:02:33Z","closed_at":null,"body":"I have made a helper class like :\r\n\r\n```php\r\nclass SocketPush\r\n{\r\n    /**\r\n     * Helper Function to broad a message.\r\n     * The metadata required to send message should be part of message itself\r\n     * Example usage:\r\n     * SocketPush::SendBroadcast(SocketPush::constructMessage(PusherServer::$PUSHABLE_USER_PREFIX . '1'\r\n     * , PusherServer::$ACTION_PUSH, \"coming your way\"));\r\n     * @param $msg string\r\n     */\r\n    public static function SendBroadcast($msg)\r\n    {\r\n        $loop = Factory::create();\r\n        $connector = new Connector($loop);\r\n        $connector('ws://127.0.0.1:8080', [], ['Origin' => 'origin'])\r\n            ->then(function (WebSocket $conn) use ($msg, $loop) {\r\n                $conn->remoteAddress = '127.0.0.1';\r\n                $conn->on('close', function ($code = null, $reason = null) {\r\n                });\r\n                $conn->send($msg);\r\n                $conn->close();\r\n            }, function (\\Exception $e) use ($loop) {\r\n                echo $e->getMessage();\r\n                $loop->stop();\r\n            });\r\n        $loop->run();\r\n    }\r\n}\r\n```\r\n\r\nI am using push notification using ratchet, and so , whenever I need the server to send a message to a client, I call the sendBroadcast method of this client. \r\nWhat this does is, everytime a message needs to be sent, it initiates a connection , then sends the message, then closes it(this sounds like unnecessary overhead)\r\n\r\nIs is possible to keep the connection open at all times (if for some reach it disconnects, reconnect), and , call the same send broadcast method from other classes to send message ?\r\n"},"comment":{"url":"https://api.github.com/repos/ratchetphp/Pawl/issues/comments/269912829","html_url":"https://github.com/ratchetphp/Pawl/issues/33#issuecomment-269912829","issue_url":"https://api.github.com/repos/ratchetphp/Pawl/issues/33","id":269912829,"user":{"login":"cboden","id":617694,"avatar_url":"https://avatars.githubusercontent.com/u/617694?v=3","gravatar_id":"","url":"https://api.github.com/users/cboden","html_url":"https://github.com/cboden","followers_url":"https://api.github.com/users/cboden/followers","following_url":"https://api.github.com/users/cboden/following{/other_user}","gists_url":"https://api.github.com/users/cboden/gists{/gist_id}","starred_url":"https://api.github.com/users/cboden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cboden/subscriptions","organizations_url":"https://api.github.com/users/cboden/orgs","repos_url":"https://api.github.com/users/cboden/repos","events_url":"https://api.github.com/users/cboden/events{/privacy}","received_events_url":"https://api.github.com/users/cboden/received_events","type":"User","site_admin":false},"created_at":"2017-01-01T18:02:33Z","updated_at":"2017-01-01T18:02:33Z","body":"Your `SocketPush` class is run inside your website (not within your Ratchet) app, correct? If so what you're doing is correct. It's the same as the push tutorial just using a different transport. With each client request to your website you do have to open and new connection every time as the environment is destroyed at the end of the request. "}}
{"actor":{"display_login":"cboden"}}