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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.