making fsockopen variable global

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manuitpro
    New Member
    • Dec 2009
    • 13

    making fsockopen variable global

    I am using class and and connection variable $this->_connection = @fsockopen($thi s->_hostname, 23, $errno, $errstr, $this->_timeout), class has other variables also. class object is global, and when i use this object in another page i am getting all other variable values except $this->connection, it is restting to zero.

    How do i make this value as global.

    Thanks
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    My experience with sockets is limited, but if you want it to persist across page requests, I would assume saving the resource into the SESSION would work until you have closed the socket. However, PHP may automatically close it after the script completes. Let me know how it goes.

    If you just want it to be accessible through other pages with a limited scope (i.e. pages included via a function call), then just use the keyword global when the resource is created, and in the file that you need it in.

    Code:
    // Main file
    function buildPage($page) {
        include $page;
    }
    
    global $data = "...";
    buildPage('some_file.php');
    Code:
    // Included file
    global $data; // This file now has access to $data

    Comment

    Working...