domino1 Posted October 18, 2007 Share Posted October 18, 2007 What i want is to open a socket on login.php, and pass it as session variable to all subsequent pages. However, this doesnt seem to work. The socket handle gets re-set to ZERO! ??? Yes, i do have a component listening on port 20505. This is so bizarre, i must be doing something wrong. socket.php: <?php session_start(); $_SESSION['langleySockets'] = array(); $_SESSION['langleySockets'][0] = array( 'hi' => 'bye', 'socket' => fsockopen("127.0.0.1", 20505)); $fh=fopen("/tmp/socket.xxx", "w");fwrite($fh, print_r($_SESSION['langleySockets'][0], true));fclose($fh); session_write_close(); header("Location: socket2.php" . "?" . SID); ?> socket2.php: <?php session_start(); $fh=fopen("/tmp/socket.xxx", "a");fwrite($fh, print_r($_SESSION['langleySockets'][0], true));fclose($fh); session_write_close(); ?> and the output is: [root@xyz db]# cat /tmp/socket.xxx Array ( [hi] => bye [socket] => Resource id #2 ) Array ( [hi] => bye [socket] => 0 ) Quote Link to comment https://forums.phpfreaks.com/topic/73850-socket-handle-not-preserved-in-session/ Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2007 Share Posted October 18, 2007 my inclination is to believe that you can't store connection resources in session variables. you're essentially saying "make this connection and keep it active until the session dies, if ever." Quote Link to comment https://forums.phpfreaks.com/topic/73850-socket-handle-not-preserved-in-session/#findComment-372593 Share on other sites More sharing options...
domino1 Posted October 18, 2007 Author Share Posted October 18, 2007 lol, what is unusual about this?? sockets are opened/handled by the O/S. php has no business meddling in this. i can wipe my own chin, thank you. you're essentially saying "make this connection and keep it active until the session dies, if ever." Quote Link to comment https://forums.phpfreaks.com/topic/73850-socket-handle-not-preserved-in-session/#findComment-372681 Share on other sites More sharing options...
btherl Posted October 19, 2007 Share Posted October 19, 2007 You can't store resources in $_SESSION. When a request terminates, all resources are closed, including your socket. Data is later reconstituted from $_SESSION on the next request, but by this time the connection has been closed, so the handle you stored in $_SESSION is meaningless. Quote Link to comment https://forums.phpfreaks.com/topic/73850-socket-handle-not-preserved-in-session/#findComment-372839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.