3.7 KiB
Using a proxy
You can use a proxy with MadelineProto.
There are two ways to do this: either buy a pre-made Socks5 or HTTP proxy for 10$, or build your own proxy.
Buying a proxy class
Just send 10$ to paypal.me/danog, specifying the the proxy you wish to receive and your telegram username.
Building a proxy class
class MyProxy implements \danog\MadelineProto\Proxy
{
//...
}
$MadelineProto->settings['connection_settings']['all']['proxy'] = '\MyProxy';
Simply create a class that implements the \danog\MadelineProto\Proxy
interface, and enter its name in the settings.
Your proxy class MUST use the \Socket
class for all TCP/UDP communications.
Your proxy class can also have a setExtra method that accepts an array as the first parameter, to pass the values provided in the proxy_extra setting.
The \Socket
class has the following methods (all of the following methods must also be implemented by your proxy class):
public function __construct(int $domain, int $type, int $protocol);
Works exactly like the socket_connect function.
public function setOption(int $level, int $name, $value);
Works exactly like the socket_set_option function.
public function getOption(int $name, $value);
Works exactly like the socket_get_option function.
public function setBlocking(bool $blocking);
Works like the socket_block or socket_nonblock functions.
public function bind(string $address, [ int $port = 0 ]);
Works exactly like the socket_bind function.
public function listen([ int $backlog = 0 ]);
Works exactly like the socket_listen function.
public function accept();
Works exactly like the socket_accept function.
public function connect(string $address, [ int $port = 0 ]);
Works exactly like the socket_accept function.
public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0);
Works exactly like the socket_select function.
public function read(int $length, [ int $flags = 0 ]);
Works exactly like the socket_read function.
public function write(string $buffer, [ int $length ]);
Works exactly like the socket_read function.
public function send(string $data, int $length, int $flags);
Works exactly like the socket_send function.
public function close();
Works exactly like the socket_close function.
public function getPeerName(bool $port = true);
Works like socket_getpeername: the difference is that it returns an array with the host
and the port
.
public function getSockName(bool $port = true);
Works like socket_getsockname: the difference is that it returns an array with the host
and the port
.
public function getProxyHeaders();
Can return additional HTTP headers to use when the HTTP protocol is being used.