请教$_SESSION作用域问题

https://github.com/walkor/workerman-chat/tree/master/Applications/Chat
 
> 在上面的例子上,我新增了 `Server.php` 和 `Client.php` 用于消息转发


1.Events.php 调用 Server 方法  (因为Events里面是静态的,不太会用,所以新建了一个类)
2.Server方法连接的时候创建AsyncTcpConnection客户端连接其他的服务端
3.客户端收到消息后通过Server发送给网页
 4.网页发送消息给server, server用AsyncTcpConnection发送给其他服务端



Events.php
public static function onMessage($client_id, $data)
{
$_SESSION['Server']->onMessage($client_id, $data);
}

public static function onConnect($client_id)
{
$_SESSION['client_id'] = $client_id;
$_SESSION['Server'] = new Server();
$_SESSION['Server']->onConnect($client_id);
}

 
Server.php
<?php

public function onConnect($client_id)
{
$serverIp = '***.***.***.***';
$serve = "ws://$serverIp:9999";
$_SESSION['ClientAsyncTcpConnection'] = new AsyncTcpConnection($serve);
$_SESSION['Client'] = new Client($client_id);
$_SESSION['Client']->serveClientId = $client_id;
$_SESSION['Client']->serverIp = $serverIp;
$_SESSION['ClientAsyncTcpConnection']->onConnect = array($_SESSION['Client'], 'onConnect');
$_SESSION['ClientAsyncTcpConnection']->onMessage = array($_SESSION['Client'], 'onMessage');
$_SESSION['ClientAsyncTcpConnection']->onError = array($_SESSION['Client'], 'onError');
$_SESSION['ClientAsyncTcpConnection']->onClose = array($_SESSION['Client'], 'onClose');
$_SESSION['ClientAsyncTcpConnection']->onError = array($_SESSION['Client'], 'onError');
$_SESSION['ClientAsyncTcpConnection']->connect();
}
public function onMessage($client_id, $data)
{
$_SESSION['Client']->onRecv($data);
}

 
Client.php
function onConnect($con)
{
$this->mCon = $con;
}
public function onRecv($data)
{
var_dump($this->mCon);
}

 
请问在 `Client.php`  里面 `var_dump($this->mCon)`为什么是NULL呢?
已邀请:
$_SESSION 只能存数组,不能存对象

西红柿

赞同来自:

这种使用场景能指点我一下吗?就是客户端服务端并存,客户但连接其他的服务端并通过自己的服务端把消息转发给网页,这种绑定关系。我该怎么存呢?

要回复问题请先登录注册