会话为NULL Memcached - Codeigniter + Ratchet

时间:2018-01-18 13:41:35

标签: php symfony session memcached ratchet

我刚安装了Memcached并使用了一些教程来设置服务器。

这是我的服务器代码:

<p style="text-align: center;">
	<span style="font-size:12px;">
		<strong>Text here.
			<div id="attachment_1111" style="max-width: 500px" class="wp-caption aligncenter">
				<img src="http://www.mywebsite/wp-content/uploads/2017/09/image-upload.jpg" alt="Text here" width="500" height="650" class="size-full wp-image-1111 wp-caption aligncenter" srcset="http://www.mywebsite/wp-content/uploads/2017/09/image-upload.jpg 500w, http://www.mywebsite/wp-content/uploads/2017/09/image-upload.jpg 225w, http://www.mywebsite/wp-content/uploads/2017/09/image-upload.jpg 450w" sizes="(max-width: 500px) 100vw, 500px" />
				<p class="wp-caption-text">
					<a href="https://www.google.com" target="_blank">
						<span style="color:#FFFFFF;">
							<span style="font-size:10px;">
								<em>google</em>
							</span>
						</span>
					</a>
				</p>
			</div>
		</strong>
	</span>
</p>

onOpen功能:

use Ratchet\Session\SessionProvider;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;

require dirname(__DIR__) . '/vendor/autoload.php';

$loop   = React\EventLoop\Factory::create();
$pusher = new MyApp\Pusher;

$memcached = new Memcached;
$memcached->addServer('0.0.0.0', 11211);

// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server('0.0.0.0:8080', $loop); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
    new Ratchet\Http\HttpServer(
        new Ratchet\Session\SessionProvider(
            new Ratchet\WebSocket\WsServer(
                new Ratchet\Wamp\WampServer(
                    $pusher
                )
            ),new Handler\MemcachedSessionHandler($memcached)
        ) 
    ),
    $webSock
);

$loop->run();

Var转储输出:

public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
$this->users[$conn->resourceId] = $conn;
    var_dump($conn->Session->all());
    echo "New connection! ({$conn->resourceId})\n";
}

我的问题是我无法在Ratchet onOpen函数中将数据发送到memcached。 我需要这个来向特定用户发送消息。我想将数据库用户ID添加到连接。

我已多次更改代码,因为我发现有更多教程尝试修复错误但现在我不知道下一步该做什么。 Memcached似乎运行良好,我可以在ssh登录时从memcached获取数据。

我想说现在我正在使用Codeigniter,在Symfony上移动所有代码会更好吗?

任何建议都会有所帮助! 谢谢!

0 个答案:

没有答案