Access Yii Session From Other App?

Hy all.

It possible access yii session data from an other application?

So… session started auto in base app and i add two data to session:

In my view file:


Yii::app()->getSession()->add('name',$user->WArtist->name);

Yii::app()->getSession()->add('gender',$user->WArtist->gender);

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);





CHttpSession Object

(

    [autoStart] => 1

    [behaviors] => Array

        (

        )


    [_initialized:CApplicationComponent:private] => 1

    [_e:CComponent:private] =>

    [_m:CComponent:private] =>

)



Solved.


\Yii::app()->session->close();

\Yii::app()->session->setSessionID($conn->WebSocket->request->getCookie(ini_get('session.name')));

\Yii::app()->session->open();

Hi Stageline,

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:

  1. event on server

  2. find clients to be addressed

  3. 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.)

Hello!

Try make new private function in your app, and call it anywhere. (i call it from onPublish event)




private function limitReached(ConnectionInterface $conn, $topic)

{

	$this->broadcast($topic,array('limitReached',\Yii::t('z3us','Character limit reached! Buy credit to remove limitations!')),null);

	$conn->close();

}



this broadcast limit reached message to connected user.

Now waiting limitreached remote call from websocket server.




$(Chat).bind('limitReached',function(e,room,msg){

   console.debug(msg);

   bootbox.alert(msg);

});



$conn var store current user connection data.