I want to use php sockets via proxy. I use the following code for socket create
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, some_ip, 443);
And setting the proxy via :
$aContext = array(
'http' => array(
'proxy' => 'tcp://191.96.x.xx:1212',
),
);
stream_context_set_default($aContext);
But when I test it using trace route it does not go through the proxy. Traceroute - https://www.adayinthelifeof.nl/2010/07/30/creating-a-traceroute-program-in-php/
Also I tried using the environment variable http_proxy=http://proxy.example.com:8080
but id doesn't go through the proxy
The stream_context_set_default
sets the default context for file operations (e.g. fopen
, file_get_contents
), but you're trying to do socket operations with socket_create
, etc - the two are very different.
If you just want to download files over HTTP via a proxy server use something like $data = file_get_contents("http://example.com/file");
after you've set the default context to use your proxy.
If you need to be using raw sockets you can use socket_create
etc, but you'll need to provide more details on what type of proxy you are using and what you want to achieve with sockets.