Jump to content

socket handle not preserved in SESSION


domino1

Recommended Posts

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
)

Link to comment
https://forums.phpfreaks.com/topic/73850-socket-handle-not-preserved-in-session/
Share on other sites

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."

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.