dongmo20030416 2015-03-02 14:14
浏览 115

带代理的php套接字

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条回答 默认 最新

  • doucai4274 2015-06-15 08:10
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b