2

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

1
  • unable to find anything much on it Commented Mar 3, 2015 at 6:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.