【问题标题】:How to test proxy or socks with php如何使用 php 测试代理或袜子
【发布时间】:2014-03-08 02:56:54
【问题描述】:

例如,如果我有代理或袜子:

218.36.xx.xxx:88xx

我如何编写代码以便测试袜子/代理是否正常工作,例如

socks work print ok if not print wrong 我搜索了很多我

没有找到解释我的问题的简单代码

【问题讨论】:

    标签: php proxy socks


    【解决方案1】:

    您可以使用这个简单的代码来测试一个代理:

    <?
    
    $ip   = "192.168.1.1";
    $port = "80";
    $curl = curl_init();
    CURL_SETOPT($curl,CURLOPT_URL,"http://google.fr");
    CURL_SETOPT($curl,CURLOPT_PROXY,$ip.":".$port);
    CURL_SETOPT($curl,CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
    CURL_SETOPT($curl,CURLOPT_TIMEOUT,20);
    CURL_SETOPT($curl,CURLOPT_RETURNTRANSFER,True);
    CURL_SETOPT($curl,CURLOPT_FOLLOWLOCATION,True);
    curl_exec($curl);
    curl_close($curl);
    ?>
    

    但是,如果您想测试多个代理,请使用 for 循环来执行此操作。

    【讨论】:

      【解决方案2】:

      你可以通过 curl 使用一个简单的代码

      <?
      $ip   = "192.168.1.1";
      $port = "80";
      $curl = curl_init();
      CURL_SETOPT($curl,CURLOPT_URL,"http://google.fr");
      CURL_SETOPT($curl,CURLOPT_PROXY,$ip.":".$port);
      CURL_SETOPT($curl,CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
      CURL_SETOPT($curl,CURLOPT_TIMEOUT,20);
      CURL_SETOPT($curl,CURLOPT_RETURNTRANSFER,True);
      CURL_SETOPT($curl,CURLOPT_FOLLOWLOCATION,True);
      curl_exec($curl);
      curl_close($curl);
      ?>
      

      它将测试从此代理访问 Google。

      【讨论】:

        【解决方案3】:

        试试这个:

        类 ListeningServerStub { 受保护的 $client;

        public function listen()
        {
            $sock = socket_create(AF_INET, SOCK_STREAM, 0);
        
            // Bind the socket to an address/port
            socket_bind($sock, 'localhost', 0) or throw new RuntimeException('Could not bind to address');
        
            // Start listening for connections
            socket_listen($sock);
        
            // Accept incoming requests and handle them as child processes.
            $this->client = socket_accept($sock);
        }
        
        public function read()
        {
            // Read the input from the client &#8211; 1024 bytes
            $input = socket_read($client, 1024);
            return $input;
        }
        

        }

        How do I unit test socket code with PHPUnit?

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-08-07
          • 2013-09-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-06-18
          相关资源
          最近更新 更多