My code is: [code] function connect_to_socket () { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_nonblock($this -> SOCKET) or die("Unable to set nonblock on socket\n"); $time = time(); while (!@socket_connect($this -> SOCKET, $this -> IPADDRESS, $this->PORT)) { $err = socket_last_error($this -> SOCKET); if ($err == 115 || $err == 114){ if ((time() - $time) >= $this -> TIMEOUT){ socket_close($this -> SOCKET); // connection timed out return(false); } sleep(1); continue; } // connection refused return(false); } socket_close($socket); return (true); } [/code] This actually works for timing out the socket (improved from yesterday) but I now have issues with reading from the socket when I am using this method (non_block etc). Unfortunaly I dont understand too much about blocking and unblocking sockets and the php manual in non too detailed :/ The code I am using to read/write from the socket (read called after writing data) is: [code] function read_from_socket() { while ($out = socket_read($this -> SOCKET, 12048)) { $response .= $out; } return ($response); } function write_to_socket($in="") { if (!socket_write($this -> SOCKET, $in, strlen($in))) { print ("Failed to send data"); } } [/code] The response is then acted upon, but the response returned when using nonblock is not the same as if I just do a plain connect (seems to be nothing returned). Cheers Mark