22 require_once
'HTTP/Request2/SocketWrapper.php';
52 $address,
$timeout = 10, array $contextOptions = array(),
53 $username = null, $password = null
55 parent::__construct($address,
$timeout, $contextOptions);
57 if (strlen($username)) {
58 $request = pack(
'C4', 5, 2, 0, 2);
60 $request = pack(
'C3', 5, 1, 0);
62 $this->
write($request);
63 $response = unpack(
'Cversion/Cmethod', $this->
read(3));
64 if (5 != $response[
'version']) {
66 'Invalid version received from SOCKS5 proxy: ' . $response[
'version'],
70 switch ($response[
'method']) {
77 "Connection rejected by proxy due to unsupported auth method"
94 $request = pack(
'C2', 1, strlen($username)) . $username
95 . pack(
'C', strlen($password)) . $password;
97 $this->
write($request);
98 $response = unpack(
'Cvn/Cstatus', $this->
read(3));
99 if (1 != $response[
'vn'] || 0 != $response[
'status']) {
101 'Connection rejected by proxy due to invalid username and/or password'
115 public function connect($remoteHost, $remotePort)
117 $request = pack(
'C5', 0x05, 0x01, 0x00, 0x03, strlen($remoteHost))
118 . $remoteHost . pack(
'n', $remotePort);
120 $this->
write($request);
121 $response = unpack(
'Cversion/Creply/Creserved', $this->
read(1024));
122 if (5 != $response[
'version'] || 0 != $response[
'reserved']) {
124 'Invalid response received from SOCKS5 proxy',
127 } elseif (0 != $response[
'reply']) {
129 "Unable to connect to {$remoteHost}:{$remotePort} through SOCKS5 proxy",
130 0, $response[
'reply']
performAuthentication($username, $password)
__construct($address, $timeout=10, array $contextOptions=array(), $username=null, $password=null)
connect($remoteHost, $remotePort)