<?php
/**
* This file is part of workerman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://m.wtbis.cn/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use \Workerman\Worker;
use \Workerman\Autoloader;
use Workerman\Lib\Timer;
use Channel\Client;
use GatewayWorker\Lib\Gateway;
use Shared\Config\nswc_timer;
use Shared\Model\Game\NSWC_Model;
use GlobalData\GClient;
use Shared\Config\nswc;
// (我一共起了 四個進程處理,發(fā)現(xiàn)當客戶端1和客戶端2 都連接到相同的進程號的時候,出現(xiàn)后邊登錄客戶端 //session 沒有跟新成功 )
// 自動加載類
require_once __DIR__ . '/../../Workerman/Autoloader.php';
Autoloader::setRootPath(__DIR__);
$task = new Worker();
// 開啟多少個進程運行定時任務,注意多進程并發(fā)問題
$task->count = 4;
$task->onWorkerStart = function($task)
{
global $global;//定義business中 共享數(shù)據(jù)單例對象
$global = new GClient('127.0.0.1:2207');
Channel\Client::connect('127.0.0.1', 2206);
$name = $task->id .'_' . nswc_timer::leave_nswc;
//添加一個離開房間的定時器
Channel\Client::on($name, function($data){
NSWC_Model::test('添加一個離開房間的定時器');
$timer_id = Timer::add('12', function ()use(&$timer_id,$data){
NSWC_Model::test('離開定時器觸發(fā)');
NSWC_Model::GetInstance()->leave_nswc($data,$data,$data);
},array(),false);
$session = array('timer_leave_nswc'=>$timer_id);
Gateway::updateSession($data , $session);
});
};
// 如果不是在根目錄啟動,則運行runAll方法
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}
這個屬于在GatewayWorker外部調用Gateway接口,類似使用GatewayClient,要在onWorkerStart里面設置下 Gateway::$registerAddress = 'register服務ip:register端口';
我找到解決方案了, walkor
session確實丟失了,
解決方法就是,要在business 業(yè)務邏輯中 保存下session : gateway::updateSession($client_id, $_SESSION);
這樣在其他的外部進程中獲取到的就是全部的session信息,要不然會丟失
怎么保存的帖下吧。
另外帖的代碼都是Worker的代碼,并不是businessWorker。
從你的代碼中并沒有看出來哪里用了GatewayWorker。
而且我也不清楚你有哪些進程,進程間關系,業(yè)務邏輯也沒有,比如哪里讀的session
<?php
/**
* This file is part of workerman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://m.wtbis.cn/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use \Workerman\Worker;
use \Workerman\Autoloader;
use Workerman\Lib\Timer;
use Channel\Client;
use GatewayWorker\Lib\Gateway;
use Shared\Config\nswc_timer;
use Shared\Model\Game\NSWC_Model;
use GlobalData\GClient;
use Shared\Config\nswc;
// (我一共起了 四個進程處理,發(fā)現(xiàn)當客戶端1和客戶端2 都連接到相同的進程號的時候,出現(xiàn)后邊登錄客戶端 //session 沒有跟新成功 )
// 自動加載類
require_once __DIR__ . '/../../Workerman/Autoloader.php';
Autoloader::setRootPath(__DIR__);
$task = new Worker();
// 開啟多少個進程運行定時任務,注意多進程并發(fā)問題
$task->count = 4;
$task->onWorkerStart = function($task)
{
Gateway::$registerAddress = '127.0.0.1:1236';
global $global;//定義business中 共享數(shù)據(jù)單例對象
$global = new GClient('127.0.0.1:2207');
Channel\Client::connect('127.0.0.1', 2206);
$name = $task->id .'_' . nswc_timer::leave_nswc;
//添加一個離開房間的定時器
Channel\Client::on($name, function($data){
NSWC_Model::test('添加一個離開房間的定時器');
$timer_id = Timer::add('12', function ()use(&$timer_id,$data){
NSWC_Model::test('離開定時器觸發(fā)');
NSWC_Model::GetInstance()->leave_nswc($data,$data,$data);
},array(),false);
$session = array('timer_leave_nswc'=>$timer_id);
Gateway::updateSession($data , $session);
});
};
// 如果不是在根目錄啟動,則運行runAll方法
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}