Fsock object value

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

    #1

    Fsock object value

    Hi All,

    I have been using fsockopen() in a function in a class. I am able to pass all the objects in a class to another page except the fsockopen () value. I have put the values of objects from the output print_r() as below

    main pages Class objects
    Cisco Object
    (
    [_hostname:priva te] => 10.10.1.49
    [_password:priva te] => cisco123
    [_username:priva te] => cisco
    [_connection:pri vate] => Resource id #3
    [_data:private] => R3#
    [_timeout:privat e] => 3
    [_prompt:private] => #
    )

    Class values transfred to another page

    Cisco Object
    (
    [_hostname:priva te] => 10.10.1.49
    [_password:priva te] => cisco123
    [_username:priva te] => cisco
    [_connection:pri vate] => 0
    [_data:private] => R3#
    [_timeout:privat e] => 3
    [_prompt:private] => #
    )

    In all other pages the [_connection:pri vate] value is resetting to 0. I have treid using class Cisco declaring class as SESSION. (session_regist er('cisco');) and global, but no hope.

    Part of my code is

    Code:
    class Cisco
    {
    
        private $_hostname;
        private $_password;
        private $_username;
        private $_connection;
        private $_data;
        private $_timeout;
        private $_prompt;
    
        public function __construct($hostname, $password, $username, $timeout = 3)
        {
            $this->_hostname = $hostname;
            $this->_password = $password;
            $this->_username = $username;
            $this->_timeout = $timeout;
    }
    
    public function connect()
        {
    
          $this->_connection = @fsockopen($this->_hostname, 23, $errno, $errstr,  $this->_timeout);
    // code continues ....
    Thanks
    Last edited by Dormilich; Dec 21 '09, 06:36 PM. Reason: Please use [code] tags when posting code
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You cannot serialize a resource. You'll have to reopen the resource on each page request.

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      HTTP is stateless. You can't maintain connections from one request to another through normal methods.

      Comment

      • manuitpro
        New Member
        • Dec 2009
        • 13

        #4
        Thanks for the reply

        Comment

        Working...