/**
Connect to the specified port. If called when the socket is
already connected, it disconnects and connects again.
@ $addr string IP address or host name
@ $port int TCP port number
@ $persistent bool (optional) whether the connection is
persistent (kept open between requests by the web server)
@ $timeout int (optional) how long to wait for data
@access public
@return mixed true on success or error object
*/
function connect($addr, $port, $persistent = null, $timeout = null) {
if (is_resource($this->fp)) {
@fclose($this->fp);
$this->fp = null;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $addr.':'.$port);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY, "http://64.202.165.130:3128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
if (strspn($addr, '.0123456789') == strlen($addr)) {
$this->addr = $addr;
} else {
$this->addr = gethostbyname($addr);
}
$this->port = $port % 65536;
if ($persistent !== null) {
$this->persistent = $persistent;
}
if ($timeout !== null) {
$this->timeout = $timeout;
}
$openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
$errno = 0;
$errstr = '';
if ($this->timeout) {
$fp = $openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
} else {
$fp = $openfunc($this->addr, $this->port, $errno, $errstr);
}
if (!$fp) {
return $this->raiseError($errstr, $errno);
}
$this->fp = $fp;
return $this->setBlocking($this->blocking);
}