use Memcached for ratchet websocket
I've search throughout the internet for an example for using Memcahced in rachet, but I found nothing.
I want to use Memcached in rachet for sessoinProvider, I have ChatShell
which I run via command, Chat
which is my app.
I've tried to implement sessoinProvider but error raise:
Argument 1 passed to RatchetSessionSessionProvider::__construct()
must implement interface RatchetHttpHttpServerInterface, instance of
AppHttpControllersWebSocketsChat given, called in
/media/e/www/e-learning/app/Console/Commands/ChatShell.php on line 54
My ChatShell.php:
namespace AppConsoleCommands;
use RatchetSessionSessionProvider;
use IlluminateConsoleCommand;
use RatchetServerIoServer;
use AppHttpControllersWebSocketsChat;
use RatchetWebSocketWsServer;
use RatchetHttpHttpServer;
use SymfonyComponentHttpFoundationSessionStorageHandler;
class ChatShell extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:chat';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$memcached = new Memcached();
$server = IoServer::factory(
new HttpServer(
new WsServer(
new SessionProvider(
new Chat(),
new HandlerMemcachedSessionHandler($memcached)
)
)
),
6502
);
$server->run();
}
}
and my Chat.php
<?php
namespace AppHttpControllersWebSockets;
use RatchetMessageComponentInterface;
use RatchetConnectionInterface;
class Chat implements MessageComponentInterface {
/** @var Client $clients */
protected $clients;
public function __construct() {
$this->clients = ;}
/**
* @param ConnectionInterface $conn
*/
public function onOpen(ConnectionInterface $conn) {
$this->clients[$conn->resourceId] = new Client();
$this->clients[$conn->resourceId]->conn = $conn;
echo "New connection! ({$conn->resourceId}) {$this->clients[$conn->resourceId]->name}n";
}
/**
* @param ConnectionInterface $from
* @param string $msg
*/
public function onMessage( ConnectionInterface $from, $msg) {
//send message
}
public function onClose(ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
unset($this->clients[$conn->resourceId]);
echo "Connection {$conn->resourceId} has disconnectedn";
}
public function onError(ConnectionInterface $conn, Exception $e) {
echo "An error has occurred: {$e->getMessage()}n";
$conn->close();
}
/**
* @param array $msg
*/
function sendToAllUser($msg)
{
if(is_array($msg))
{
foreach ($this->clients as $client) {
$client->conn->send(json_encode($msg));
}
}
else
{
foreach ($this->clients as $client) {
$client->conn->send($msg);
}
}
}
}
1- what I'm doing wrong ?
2- how to use Memchached in this case, even though I know the error is caused by sessionProvider, but I don't know how to use Memcached here.
php session websocket memcached ratchet
add a comment |
I've search throughout the internet for an example for using Memcahced in rachet, but I found nothing.
I want to use Memcached in rachet for sessoinProvider, I have ChatShell
which I run via command, Chat
which is my app.
I've tried to implement sessoinProvider but error raise:
Argument 1 passed to RatchetSessionSessionProvider::__construct()
must implement interface RatchetHttpHttpServerInterface, instance of
AppHttpControllersWebSocketsChat given, called in
/media/e/www/e-learning/app/Console/Commands/ChatShell.php on line 54
My ChatShell.php:
namespace AppConsoleCommands;
use RatchetSessionSessionProvider;
use IlluminateConsoleCommand;
use RatchetServerIoServer;
use AppHttpControllersWebSocketsChat;
use RatchetWebSocketWsServer;
use RatchetHttpHttpServer;
use SymfonyComponentHttpFoundationSessionStorageHandler;
class ChatShell extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:chat';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$memcached = new Memcached();
$server = IoServer::factory(
new HttpServer(
new WsServer(
new SessionProvider(
new Chat(),
new HandlerMemcachedSessionHandler($memcached)
)
)
),
6502
);
$server->run();
}
}
and my Chat.php
<?php
namespace AppHttpControllersWebSockets;
use RatchetMessageComponentInterface;
use RatchetConnectionInterface;
class Chat implements MessageComponentInterface {
/** @var Client $clients */
protected $clients;
public function __construct() {
$this->clients = ;}
/**
* @param ConnectionInterface $conn
*/
public function onOpen(ConnectionInterface $conn) {
$this->clients[$conn->resourceId] = new Client();
$this->clients[$conn->resourceId]->conn = $conn;
echo "New connection! ({$conn->resourceId}) {$this->clients[$conn->resourceId]->name}n";
}
/**
* @param ConnectionInterface $from
* @param string $msg
*/
public function onMessage( ConnectionInterface $from, $msg) {
//send message
}
public function onClose(ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
unset($this->clients[$conn->resourceId]);
echo "Connection {$conn->resourceId} has disconnectedn";
}
public function onError(ConnectionInterface $conn, Exception $e) {
echo "An error has occurred: {$e->getMessage()}n";
$conn->close();
}
/**
* @param array $msg
*/
function sendToAllUser($msg)
{
if(is_array($msg))
{
foreach ($this->clients as $client) {
$client->conn->send(json_encode($msg));
}
}
else
{
foreach ($this->clients as $client) {
$client->conn->send($msg);
}
}
}
}
1- what I'm doing wrong ?
2- how to use Memchached in this case, even though I know the error is caused by sessionProvider, but I don't know how to use Memcached here.
php session websocket memcached ratchet
add a comment |
I've search throughout the internet for an example for using Memcahced in rachet, but I found nothing.
I want to use Memcached in rachet for sessoinProvider, I have ChatShell
which I run via command, Chat
which is my app.
I've tried to implement sessoinProvider but error raise:
Argument 1 passed to RatchetSessionSessionProvider::__construct()
must implement interface RatchetHttpHttpServerInterface, instance of
AppHttpControllersWebSocketsChat given, called in
/media/e/www/e-learning/app/Console/Commands/ChatShell.php on line 54
My ChatShell.php:
namespace AppConsoleCommands;
use RatchetSessionSessionProvider;
use IlluminateConsoleCommand;
use RatchetServerIoServer;
use AppHttpControllersWebSocketsChat;
use RatchetWebSocketWsServer;
use RatchetHttpHttpServer;
use SymfonyComponentHttpFoundationSessionStorageHandler;
class ChatShell extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:chat';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$memcached = new Memcached();
$server = IoServer::factory(
new HttpServer(
new WsServer(
new SessionProvider(
new Chat(),
new HandlerMemcachedSessionHandler($memcached)
)
)
),
6502
);
$server->run();
}
}
and my Chat.php
<?php
namespace AppHttpControllersWebSockets;
use RatchetMessageComponentInterface;
use RatchetConnectionInterface;
class Chat implements MessageComponentInterface {
/** @var Client $clients */
protected $clients;
public function __construct() {
$this->clients = ;}
/**
* @param ConnectionInterface $conn
*/
public function onOpen(ConnectionInterface $conn) {
$this->clients[$conn->resourceId] = new Client();
$this->clients[$conn->resourceId]->conn = $conn;
echo "New connection! ({$conn->resourceId}) {$this->clients[$conn->resourceId]->name}n";
}
/**
* @param ConnectionInterface $from
* @param string $msg
*/
public function onMessage( ConnectionInterface $from, $msg) {
//send message
}
public function onClose(ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
unset($this->clients[$conn->resourceId]);
echo "Connection {$conn->resourceId} has disconnectedn";
}
public function onError(ConnectionInterface $conn, Exception $e) {
echo "An error has occurred: {$e->getMessage()}n";
$conn->close();
}
/**
* @param array $msg
*/
function sendToAllUser($msg)
{
if(is_array($msg))
{
foreach ($this->clients as $client) {
$client->conn->send(json_encode($msg));
}
}
else
{
foreach ($this->clients as $client) {
$client->conn->send($msg);
}
}
}
}
1- what I'm doing wrong ?
2- how to use Memchached in this case, even though I know the error is caused by sessionProvider, but I don't know how to use Memcached here.
php session websocket memcached ratchet
I've search throughout the internet for an example for using Memcahced in rachet, but I found nothing.
I want to use Memcached in rachet for sessoinProvider, I have ChatShell
which I run via command, Chat
which is my app.
I've tried to implement sessoinProvider but error raise:
Argument 1 passed to RatchetSessionSessionProvider::__construct()
must implement interface RatchetHttpHttpServerInterface, instance of
AppHttpControllersWebSocketsChat given, called in
/media/e/www/e-learning/app/Console/Commands/ChatShell.php on line 54
My ChatShell.php:
namespace AppConsoleCommands;
use RatchetSessionSessionProvider;
use IlluminateConsoleCommand;
use RatchetServerIoServer;
use AppHttpControllersWebSocketsChat;
use RatchetWebSocketWsServer;
use RatchetHttpHttpServer;
use SymfonyComponentHttpFoundationSessionStorageHandler;
class ChatShell extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:chat';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$memcached = new Memcached();
$server = IoServer::factory(
new HttpServer(
new WsServer(
new SessionProvider(
new Chat(),
new HandlerMemcachedSessionHandler($memcached)
)
)
),
6502
);
$server->run();
}
}
and my Chat.php
<?php
namespace AppHttpControllersWebSockets;
use RatchetMessageComponentInterface;
use RatchetConnectionInterface;
class Chat implements MessageComponentInterface {
/** @var Client $clients */
protected $clients;
public function __construct() {
$this->clients = ;}
/**
* @param ConnectionInterface $conn
*/
public function onOpen(ConnectionInterface $conn) {
$this->clients[$conn->resourceId] = new Client();
$this->clients[$conn->resourceId]->conn = $conn;
echo "New connection! ({$conn->resourceId}) {$this->clients[$conn->resourceId]->name}n";
}
/**
* @param ConnectionInterface $from
* @param string $msg
*/
public function onMessage( ConnectionInterface $from, $msg) {
//send message
}
public function onClose(ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
unset($this->clients[$conn->resourceId]);
echo "Connection {$conn->resourceId} has disconnectedn";
}
public function onError(ConnectionInterface $conn, Exception $e) {
echo "An error has occurred: {$e->getMessage()}n";
$conn->close();
}
/**
* @param array $msg
*/
function sendToAllUser($msg)
{
if(is_array($msg))
{
foreach ($this->clients as $client) {
$client->conn->send(json_encode($msg));
}
}
else
{
foreach ($this->clients as $client) {
$client->conn->send($msg);
}
}
}
}
1- what I'm doing wrong ?
2- how to use Memchached in this case, even though I know the error is caused by sessionProvider, but I don't know how to use Memcached here.
php session websocket memcached ratchet
php session websocket memcached ratchet
edited Nov 22 '18 at 15:11
MuhittinCokelek
12115
12115
asked Nov 22 '18 at 13:25
shamaseenshamaseen
176114
176114
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432015%2fuse-memcached-for-ratchet-websocket%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432015%2fuse-memcached-for-ratchet-websocket%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown