How can i get (name,gender) session data from other app? This script run from console like php -f xyz.pph
<?php
namespace MyApp;
ini_set('display_errors',1);
ini_set('error_reporting',E_ALL);
use Ratchet\ConnectionInterface;
use Ratchet\Wamp\WampServerInterface;
// change the following paths if necessary
$yii = '/var/www/z3us/yii/framework/yii.php';
$config = '/var/www/z3us/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
require_once($yii);
\Yii::createWebApplication($config);
\Yii::app()->session->setSessionID( $conn->WebSocket->request->getCookie(ini_get('session.name')) );
print_r(\Yii::app()->session);
It looks like have integrated the Ratchet Webserver with a Yii application. I am looking to do the same thing. I would greatly appreciate if you could elaborate a little more on how you did this.
My use case, which may be similar to yours, would require the following: When an event on the server has occurred, a message needs to be prepared. This message needs to be pushed via a websocket to some clients.
Here is how I envision this to work
In a Yii app:
event on server
find clients to be addressed
open a ZeroMQ connection ZMQContext() to websocket server and send (encoded) message with a list of userID’s to be addressed.
All of the above would concur with this Ratchet tutorial.
But now, my problem starts. I suppose the webserver would send the websocket message with something like
$topic->broadcast($message);
My problem: But how can the Websocket server know which of its connections/client to address? How can it match websocket connection to user ID’s?
(I understand that the only way to do this is with sessionID’s. But I am wondering how to approach this.)