Results 1 to 5 of 5

Thread: Save object in PHP session

  1. #1
    dilukhin is offline Registered User
    Name: Dmitry Ilukhin
    Organization: Telros
    Project: Rubin
    Join Date
    Jan 2011
    Posts
    15

    Save object in PHP session

    We developing a web app that uses Ice and PHP. In each PHP page we create Ice communicator using Ice_Initialize() with some init data, then get router through getDefaultRouter, then create session from router using login and password stored in PHP $_SESSION . Each time that done, the PermissionsVerifier asks database for login/password validity and then creates a servant object. So, each page visit and each async Ajax query does authenicate and create new object. Turning on logging for authentication process, we get a bunch of messages that says "User xxx logged in". We was trying to find a way to save proxy object between queries (using Ice_Find(), stringToProxy(), proxyToString() etc) to keep it alive and not need to save login/password in PHP session, but no success, we get null object from stringToProxy(). Is this saving possible in any way? Or maybe login info saving in PHP session method is a common way for writing authenticated Ice'd applications in PHP?

  2. #2
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    Hi Dmitry,

    The lifetime of a Glacier2 session is limited to the lifetime of the connection between the client and the router. Furthermore, the session can only be used by this originating connection. Once the connection is closed for any reason, the session can no longer be used and becomes eligible for destruction.

    These semantics make it difficult to use a Glacier2 router from PHP. The Ice extension for PHP automatically destroys your communicator at the end of each PHP request, which means all connections established by that communicator are closed.

    Ice does provide a solution for this, we call it "registered communicators." Briefly, the PHP script notifies Ice that a communicator instance should not be destroyed at the end of the request. This allows a subsequent request to retrieve that instance and continue to use it.

    For this to work, PHP requests need to be serviced by the same Web server process. (A communicator instance is "alive" inside a persistent Web server process, so the only way two successive PHP requests can reuse the same communicator is if those requests are executed by the same process.) Depending on the Web server you are using, this may or may not be difficult to accomplish. For example, you could configure an Apache instance to have at most only one child process, but of course that might limit your application's responsiveness.

    If you haven't already seen it, Ice for PHP includes a Glacier2 example in the demo/Glacier2/hello directory.

    Regards,
    Mark

  3. #3
    dilukhin is offline Registered User
    Name: Dmitry Ilukhin
    Organization: Telros
    Project: Rubin
    Join Date
    Jan 2011
    Posts
    15
    Hi Mark,
    Thanks for comprehensive answer. My web server is configured to use PHP in single process, so registered communicator is working. Ice_register($ICE, session_id(), session_cache_expire()) in one page allows me to get working communicator pointer when i use $ICE = Ice_find(session_id()) in another. But communicator is not only i need, another object i get from it is router:
    PHP Code:
    $router Glacier2_RouterPrxHelper::checkedCast($ICE->getDefaultRouter());
    //and finally
    $dbshell=Meteor_IDbShellPrxHelper::uncheckedCast($session=$router->createSession($user$password)); 
    the last one is a subject to save between sessions, i can do it that way:
    PHP Code:
    $_SESSION["obj_dbshell"] = $ICE->proxyToString($dbshell);
    // String here is like "92b32ff4-7d09-4a12-8e39-59163928999b -t:tcp -h 192.168.0.12 -p 10001"
    // IP address is an ICE server 
    and in another page, restore:
    PHP Code:
    $dbshell=Meteor_IDbShellPrxHelper::checkedCast($ICE->stringToProxy($_SESSION["obj_dbshell"])); 
    When second page refreshed frequently, all works fine. The only trouble is, if i wait 15-20 seconds, then refresh it, call checkedCast throws Ice_ConnectionLostException. When i do, i have again to get router and call createSession() on it, thus complete login procedure each time page refreshed. Need some guru's help on it, where is this little timeout from, and how to increase it to appropriate value (session_expire() returns 180, so 180 minutes would be fine )
    Last edited by dilukhin; 08-12-2011 at 04:59 AM.

  4. #4
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    Hi,

    I'm glad to hear you got it working.

    Regarding the ConnectionLostException, there are two settings you should check. First, you must disable client-side active connection management by setting Ice.ACM.Client=0 in your PHP script. This feature automatically closes idle connections (after 60 seconds by default), and we generally recommend disabling it when using Glacier2.

    Second, review the setting for Glacier2.SessionTimeout in your Glacier2 configuration. Setting this property to a non-zero value enables automatic session destruction after a session has been idle for the given number of seconds.

    Hope that helps,
    Mark

  5. #5
    dilukhin is offline Registered User
    Name: Dmitry Ilukhin
    Organization: Telros
    Project: Rubin
    Join Date
    Jan 2011
    Posts
    15
    Hi Mark,
    Seems it is working now. Ice.ACM.Client was 0 already, setting Glacier2.SessionTimeout to zero i've got no timeouts and lost connections. Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Ice Client Connection , how to save on round trips ?
    By Faiz.Usmani in forum Help Center
    Replies: 7
    Last Post: 06-23-2008, 11:00 AM
  2. Replies: 6
    Last Post: 03-14-2008, 10:38 PM
  3. Ice::Properties save
    By ctennis in forum Comments
    Replies: 0
    Last Post: 03-07-2007, 01:12 PM
  4. Adding To Evictor Enough To Save
    By acbell in forum Help Center
    Replies: 2
    Last Post: 02-21-2006, 05:19 PM
  5. is there any function in ice to save properties?
    By xiehua in forum Help Center
    Replies: 11
    Last Post: 11-15-2005, 12:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •