I have written a browser class, and while the connect method seems to work 
ok (it times out after 10 seconds, as desired), I'm having problems with 
actually writing to the socket. For unreliable servers, it has taken up 
to 15 minutes to write to the socket, whereas I would like the script to 
give up after only a few seconds. I have tried:

if ($this->connection->socket) socket_set_timeout($this->connection->socket,
1);

setting the socket timeout to 1 second, but it only serves to aggravate 
the problem. Am I doing something wrong? Is there some way to get it to 
give up writing to the socket after a few seconds? [I'm using the latest 
stable PHP, freshly compiled on Open BSD; socket_set_timeout does appear 
to be working, but not as I desire.

(my browser constructor looks like this:
                $this->ua=$ua;
                $this->host=$host;
                $this->proxy=$proxy;
                if ($proxy) $this->connection=new 
connection($proxy,$proxyport,$timeout);
                else $this->connection=new connection($host);
                if (!$this->connection->socket) $this->failure=1; // failure :-(
//              if ($this->connection->socket) socket_set_timeout($this->connection-
>socket,1);
also
class connection { // This is a low-level socket class. 
        function connection($host,$port=80,$timeout=10) {
                if (!$host) "You need a host!";
                $this->socket=fsockopen($host,$port,&$errno,&$errtext,$timeout);
        }
        function close() {
                fclose($this->socket);
        }
        function put($string) {
                if (!$string) die("missing argument \$string to connection->put");     
         
                if (!$this->socket) return 0;
                fputs($this->socket,$string);
                return 1;
        }
        function get($packet=128) { // Packet size
                if (!$this->socket) return 0;
                return fgets($this->socket,$packet);
        }
}

)


Free, encrypted, secure Web-based email at www.hushmail.com
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to