{"id":675,"date":"2025-11-19T11:51:51","date_gmt":"2025-11-19T03:51:51","guid":{"rendered":"https:\/\/help.ipnut.com\/?post_type=docs&#038;p=675"},"modified":"2025-12-03T17:50:11","modified_gmt":"2025-12-03T09:50:11","password":"","slug":"tong-guo-php-yu-yan-jie-ru-dai-ma-demo","status":"publish","type":"docs","link":"https:\/\/www.ipnut.com\/cn\/help\/kai-fa-wen-dang\/tong-guo-php-yu-yan-jie-ru-dai-ma-demo\/","title":{"rendered":"\u901a\u8fc7PHP\u8bed\u8a00\u63a5\u5165\u4ee3\u7801Demo"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"675\" class=\"elementor elementor-675\" data-elementor-post-type=\"docs\">\n\t\t\t\t<div class=\"elementor-element elementor-element-b92db2b e-flex e-con-boxed e-con e-parent\" data-id=\"b92db2b\" data-element_type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-f14bc85 elementor-widget elementor-widget-text-editor\" data-id=\"f14bc85\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p style=\"font-size: 18px; font-style: normal; font-weight: 400;\">\u901a\u8fc7PHP\u8bed\u8a00\u914d\u7f6eIPNut \u4ee3\u7406\uff1a<\/p><p style=\"font-size: 18px; font-style: normal; font-weight: 400;\">\u8fdb\u5165\u00a0<span style=\"font-weight: bold;\"><a style=\"color: #046bd2; transition-property: all;\" href=\"https:\/\/www.ipnut.com\/cn\/\" target=\"_blank\" rel=\"noopener nofollow\">IPNut<\/a><\/span>\u00a0\u5e73\u53f0\u8d2d\u4e70\u5e76\u83b7\u53d6\u4fe1\u606f\uff0c\u8fd9\u91cc\u4ee5\u9759\u6001IP\u4e3a\u4f8b\uff08\u5047\u5982\u7aef\u53e3\u662f http:\/\/proxy.ipnut.com:28001\uff0c\u8d26\u53f7: ipnut\uff0c\u5bc6\u7801: 123456789\uff09\u3002<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8f5bb58 elementor-widget elementor-widget-heading\" data-id=\"8f5bb58\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\"><span style=\"font-size: 16px\">1. SOCKS5\u4ee3\u7406\u793a\u4f8b<\/span><span style=\"font-size: 16px\"><\/span><span style=\"font-size: 16px\"><\/span><\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e122913 elementor-widget elementor-widget-code-highlight\" data-id=\"e122913\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-php \">\n\t\t\t\t<code readonly=\"true\" class=\"language-php\">\n\t\t\t\t\t<xmp><?php\r\n\/**\r\n * SOCKS5\u4ee3\u7406\u6f14\u793a\r\n *\/\r\n\r\nclass Socks5ProxyDemo {\r\n    \r\n    private $proxy_host = 'proxy.ipnut.com';\r\n    private $proxy_port = 28001;\r\n    private $proxy_username = 'ipnut';\r\n    private $proxy_password = '123456789';\r\n    \r\n    \/**\r\n     * \u4f7f\u7528cURL\u7684SOCKS5\u4ee3\u7406\r\n     *\/\r\n    public function socks5WithCurl() {\r\n        echo \"=== \u4f7f\u7528cURL\u7684SOCKS5\u4ee3\u7406 ===\\n\";\r\n        \r\n        $ch = curl_init();\r\n        \r\n        try {\r\n            \/\/ \u8bbe\u7f6ecURL\u9009\u9879\r\n            curl_setopt_array($ch, [\r\n                CURLOPT_URL => 'http:\/\/httpbin.org\/ip',\r\n                CURLOPT_RETURNTRANSFER => true,\r\n                CURLOPT_TIMEOUT => 30,\r\n                CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n                CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,\r\n                CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n                CURLOPT_USERAGENT => 'PHP-SOCKS5-Proxy\/1.0',\r\n                CURLOPT_SSL_VERIFYPEER => false, \/\/ \u4ec5\u6d4b\u8bd5\u4f7f\u7528\r\n                CURLOPT_SSL_VERIFYHOST => false\r\n            ]);\r\n            \r\n            $response = curl_exec($ch);\r\n            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n            \r\n            if (curl_error($ch)) {\r\n                throw new Exception('cURL\u9519\u8bef: ' . curl_error($ch));\r\n            }\r\n            \r\n            echo \"\u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n            echo \"\u54cd\u5e94\u5185\u5bb9: \" . $response . \"\\n\";\r\n            \r\n        } catch (Exception $e) {\r\n            echo \"\u8bf7\u6c42\u5931\u8d25: \" . $e->getMessage() . \"\\n\";\r\n        } finally {\r\n            curl_close($ch);\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * SOCKS5\u4ee3\u7406\u591a\u8bf7\u6c42\u6f14\u793a\r\n     *\/\r\n    public function socks5MultipleRequests() {\r\n        echo \"\\n=== SOCKS5\u4ee3\u7406\u591a\u8bf7\u6c42\u6f14\u793a ===\\n\";\r\n        \r\n        $urls = [\r\n            'http:\/\/httpbin.org\/ip',\r\n            'http:\/\/httpbin.org\/user-agent',\r\n            'http:\/\/httpbin.org\/headers'\r\n        ];\r\n        \r\n        foreach ($urls as $index => $url) {\r\n            echo \"\\n\u8bf7\u6c42 \" . ($index + 1) . \": \" . $url . \"\\n\";\r\n            \r\n            $ch = curl_init();\r\n            curl_setopt_array($ch, [\r\n                CURLOPT_URL => $url,\r\n                CURLOPT_RETURNTRANSFER => true,\r\n                CURLOPT_TIMEOUT => 30,\r\n                CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n                CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,\r\n                CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n                CURLOPT_USERAGENT => 'PHP-SOCKS5-Multi\/1.0',\r\n                CURLOPT_SSL_VERIFYPEER => false\r\n            ]);\r\n            \r\n            $response = curl_exec($ch);\r\n            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n            \r\n            if (curl_error($ch)) {\r\n                echo \"\u8bf7\u6c42\u5931\u8d25: \" . curl_error($ch) . \"\\n\";\r\n            } else {\r\n                echo \"\u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n                $data = json_decode($response, true);\r\n                echo \"\u54cd\u5e94\u6458\u8981: \" . substr($response, 0, 150) . \"...\\n\";\r\n            }\r\n            \r\n            curl_close($ch);\r\n            sleep(1); \/\/ \u907f\u514d\u8bf7\u6c42\u8fc7\u5feb\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * SOCKS5\u4ee3\u7406\u81ea\u5b9a\u4e49\u8bf7\u6c42\r\n     *\/\r\n    public function socks5CustomRequest() {\r\n        echo \"\\n=== SOCKS5\u4ee3\u7406\u81ea\u5b9a\u4e49\u8bf7\u6c42 ===\\n\";\r\n        \r\n        $ch = curl_init();\r\n        \r\n        try {\r\n            $headers = [\r\n                'User-Agent: PHP-SOCKS5-Custom\/1.0',\r\n                'Accept: application\/json',\r\n                'Content-Type: application\/json'\r\n            ];\r\n            \r\n            curl_setopt_array($ch, [\r\n                CURLOPT_URL => 'https:\/\/httpbin.org\/post',\r\n                CURLOPT_RETURNTRANSFER => true,\r\n                CURLOPT_TIMEOUT => 30,\r\n                CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n                CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,\r\n                CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n                CURLOPT_POST => true,\r\n                CURLOPT_POSTFIELDS => json_encode([\r\n                    'name' => 'ipnut_user',\r\n                    'email' => 'user@ipnut.com',\r\n                    'message' => '\u6d4b\u8bd5SOCKS5\u4ee3\u7406\u8fde\u63a5'\r\n                ]),\r\n                CURLOPT_HTTPHEADER => $headers,\r\n                CURLOPT_SSL_VERIFYPEER => false\r\n            ]);\r\n            \r\n            $response = curl_exec($ch);\r\n            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n            \r\n            if (curl_error($ch)) {\r\n                throw new Exception('cURL\u9519\u8bef: ' . curl_error($ch));\r\n            }\r\n            \r\n            echo \"\u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n            echo \"\u54cd\u5e94\u5185\u5bb9: \" . $response . \"\\n\";\r\n            \r\n        } catch (Exception $e) {\r\n            echo \"POST\u8bf7\u6c42\u5931\u8d25: \" . $e->getMessage() . \"\\n\";\r\n        } finally {\r\n            curl_close($ch);\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * \u8fd0\u884c\u6240\u6709SOCKS5\u6f14\u793a\r\n     *\/\r\n    public function runAll() {\r\n        echo \"\u5f00\u59cbSOCKS5\u4ee3\u7406\u6d4b\u8bd5...\\n\\n\";\r\n        \r\n        $this->socks5WithCurl();\r\n        $this->socks5MultipleRequests();\r\n        $this->socks5CustomRequest();\r\n        \r\n        echo \"\\nSOCKS5\u4ee3\u7406\u6d4b\u8bd5\u5b8c\u6210!\\n\";\r\n    }\r\n}\r\n\r\n\/\/ \u8fd0\u884cSOCKS5\u6f14\u793a\r\n$socks5Demo = new Socks5ProxyDemo();\r\n$socks5Demo->runAll();\r\n?><\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-92fc2f3 elementor-widget elementor-widget-heading\" data-id=\"92fc2f3\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">2. HTTP\u4ee3\u7406\u793a\u4f8b<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-841b52a elementor-widget elementor-widget-code-highlight\" data-id=\"841b52a\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-php \">\n\t\t\t\t<code readonly=\"true\" class=\"language-php\">\n\t\t\t\t\t<xmp><?php\r\n\/**\r\n * HTTP\u4ee3\u7406\u6f14\u793a\r\n *\/\r\n\r\nclass HttpProxyDemo {\r\n    \r\n    private $proxy_host = 'proxy.ipnut.com';\r\n    private $proxy_port = 28001;\r\n    private $proxy_username = 'ipnut';\r\n    private $proxy_password = '123456789';\r\n    \r\n    \/**\r\n     * \u4f7f\u7528cURL\u7684HTTP\u4ee3\u7406\r\n     *\/\r\n    public function httpWithCurl() {\r\n        echo \"=== \u4f7f\u7528cURL\u7684HTTP\u4ee3\u7406 ===\\n\";\r\n        \r\n        $ch = curl_init();\r\n        \r\n        try {\r\n            \/\/ \u8bbe\u7f6ecURL\u9009\u9879\r\n            curl_setopt_array($ch, [\r\n                CURLOPT_URL => 'http:\/\/httpbin.org\/ip',\r\n                CURLOPT_RETURNTRANSFER => true,\r\n                CURLOPT_TIMEOUT => 30,\r\n                CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n                CURLOPT_PROXYTYPE => CURLPROXY_HTTP,\r\n                CURLOPT_PROXYAUTH => CURLAUTH_BASIC,\r\n                CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n                CURLOPT_USERAGENT => 'PHP-HTTP-Proxy\/1.0',\r\n                CURLOPT_SSL_VERIFYPEER => false\r\n            ]);\r\n            \r\n            $response = curl_exec($ch);\r\n            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n            \r\n            if (curl_error($ch)) {\r\n                throw new Exception('cURL\u9519\u8bef: ' . curl_error($ch));\r\n            }\r\n            \r\n            echo \"\u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n            echo \"\u54cd\u5e94\u5185\u5bb9: \" . $response . \"\\n\";\r\n            \r\n        } catch (Exception $e) {\r\n            echo \"\u8bf7\u6c42\u5931\u8d25: \" . $e->getMessage() . \"\\n\";\r\n        } finally {\r\n            curl_close($ch);\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * HTTP\u4ee3\u7406\u4e0a\u4e0b\u6587\u6d41\r\n     *\/\r\n    public function httpWithStream() {\r\n        echo \"\\n=== \u4f7f\u7528\u6d41\u4e0a\u4e0b\u6587\u7684HTTP\u4ee3\u7406 ===\\n\";\r\n        \r\n        try {\r\n            \/\/ \u521b\u5efa\u6d41\u4e0a\u4e0b\u6587\r\n            $context = stream_context_create([\r\n                'http' => [\r\n                    'proxy' => 'tcp:\/\/' . $this->proxy_host . ':' . $this->proxy_port,\r\n                    'request_fulluri' => true,\r\n                    'header' => [\r\n                        'Proxy-Authorization: Basic ' . base64_encode($this->proxy_username . ':' . $this->proxy_password),\r\n                        'User-Agent: PHP-Stream-Proxy\/1.0'\r\n                    ],\r\n                    'timeout' => 30\r\n                ],\r\n                'ssl' => [\r\n                    'verify_peer' => false,\r\n                    'verify_peer_name' => false\r\n                ]\r\n            ]);\r\n            \r\n            $response = file_get_contents('http:\/\/httpbin.org\/ip', false, $context);\r\n            \r\n            \/\/ \u83b7\u53d6HTTP\u72b6\u6001\u7801\r\n            $statusLine = $http_response_header[0] ?? '';\r\n            preg_match('\/HTTP\\\/\\d\\.\\d\\s+(\\d+)\/', $statusLine, $matches);\r\n            $httpCode = $matches[1] ?? '\u672a\u77e5';\r\n            \r\n            echo \"\u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n            echo \"\u54cd\u5e94\u5185\u5bb9: \" . $response . \"\\n\";\r\n            \r\n        } catch (Exception $e) {\r\n            echo \"\u6d41\u8bf7\u6c42\u5931\u8d25: \" . $e->getMessage() . \"\\n\";\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * HTTP\u4ee3\u7406\u591a\u8bf7\u6c42\u6f14\u793a\r\n     *\/\r\n    public function httpMultipleRequests() {\r\n        echo \"\\n=== HTTP\u4ee3\u7406\u591a\u8bf7\u6c42\u6f14\u793a ===\\n\";\r\n        \r\n        $urls = [\r\n            'http:\/\/httpbin.org\/ip',\r\n            'http:\/\/httpbin.org\/user-agent',\r\n            'http:\/\/httpbin.org\/get?param1=value1&param2=value2'\r\n        ];\r\n        \r\n        $multiHandle = curl_multi_init();\r\n        $handles = [];\r\n        \r\n        foreach ($urls as $index => $url) {\r\n            $ch = curl_init();\r\n            curl_setopt_array($ch, [\r\n                CURLOPT_URL => $url,\r\n                CURLOPT_RETURNTRANSFER => true,\r\n                CURLOPT_TIMEOUT => 30,\r\n                CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n                CURLOPT_PROXYTYPE => CURLPROXY_HTTP,\r\n                CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n                CURLOPT_USERAGENT => 'PHP-HTTP-Multi\/1.0',\r\n                CURLOPT_SSL_VERIFYPEER => false\r\n            ]);\r\n            \r\n            curl_multi_add_handle($multiHandle, $ch);\r\n            $handles[$index] = $ch;\r\n        }\r\n        \r\n        \/\/ \u6267\u884c\u591a\u8bf7\u6c42\r\n        $running = null;\r\n        do {\r\n            curl_multi_exec($multiHandle, $running);\r\n            curl_multi_select($multiHandle);\r\n        } while ($running > 0);\r\n        \r\n        \/\/ \u5904\u7406\u7ed3\u679c\r\n        foreach ($handles as $index => $ch) {\r\n            echo \"\\n\u8bf7\u6c42 \" . ($index + 1) . \": \" . $urls[$index] . \"\\n\";\r\n            \r\n            $response = curl_multi_getcontent($ch);\r\n            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n            \r\n            if (curl_error($ch)) {\r\n                echo \"\u8bf7\u6c42\u5931\u8d25: \" . curl_error($ch) . \"\\n\";\r\n            } else {\r\n                echo \"\u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n                echo \"\u54cd\u5e94\u6458\u8981: \" . substr($response, 0, 150) . \"...\\n\";\r\n            }\r\n            \r\n            curl_multi_remove_handle($multiHandle, $ch);\r\n            curl_close($ch);\r\n        }\r\n        \r\n        curl_multi_close($multiHandle);\r\n    }\r\n    \r\n    \/**\r\n     * HTTP\u4ee3\u7406POST\u8bf7\u6c42\r\n     *\/\r\n    public function httpPostRequest() {\r\n        echo \"\\n=== HTTP\u4ee3\u7406POST\u8bf7\u6c42 ===\\n\";\r\n        \r\n        $ch = curl_init();\r\n        \r\n        try {\r\n            $postData = [\r\n                'name' => 'ipnut_user',\r\n                'email' => 'user@ipnut.com',\r\n                'message' => '\u6d4b\u8bd5HTTP\u4ee3\u7406POST\u8bf7\u6c42'\r\n            ];\r\n            \r\n            $headers = [\r\n                'Content-Type: application\/json',\r\n                'User-Agent: PHP-HTTP-POST\/1.0'\r\n            ];\r\n            \r\n            curl_setopt_array($ch, [\r\n                CURLOPT_URL => 'https:\/\/httpbin.org\/post',\r\n                CURLOPT_RETURNTRANSFER => true,\r\n                CURLOPT_TIMEOUT => 30,\r\n                CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n                CURLOPT_PROXYTYPE => CURLPROXY_HTTP,\r\n                CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n                CURLOPT_POST => true,\r\n                CURLOPT_POSTFIELDS => json_encode($postData),\r\n                CURLOPT_HTTPHEADER => $headers,\r\n                CURLOPT_SSL_VERIFYPEER => false\r\n            ]);\r\n            \r\n            $response = curl_exec($ch);\r\n            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n            \r\n            if (curl_error($ch)) {\r\n                throw new Exception('cURL\u9519\u8bef: ' . curl_error($ch));\r\n            }\r\n            \r\n            echo \"\u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n            $result = json_decode($response, true);\r\n            echo \"\u54cd\u5e94\u6570\u636e: \\n\";\r\n            print_r($result['json'] ?? $response);\r\n            \r\n        } catch (Exception $e) {\r\n            echo \"POST\u8bf7\u6c42\u5931\u8d25: \" . $e->getMessage() . \"\\n\";\r\n        } finally {\r\n            curl_close($ch);\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * \u8fd0\u884c\u6240\u6709HTTP\u6f14\u793a\r\n     *\/\r\n    public function runAll() {\r\n        echo \"\u5f00\u59cbHTTP\u4ee3\u7406\u6d4b\u8bd5...\\n\\n\";\r\n        \r\n        $this->httpWithCurl();\r\n        $this->httpWithStream();\r\n        $this->httpMultipleRequests();\r\n        $this->httpPostRequest();\r\n        \r\n        echo \"\\nHTTP\u4ee3\u7406\u6d4b\u8bd5\u5b8c\u6210!\\n\";\r\n    }\r\n}\r\n\r\n\/\/ \u8fd0\u884cHTTP\u6f14\u793a\r\n$httpDemo = new HttpProxyDemo();\r\n$httpDemo->runAll();\r\n?><\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-05b6ed0 elementor-widget elementor-widget-heading\" data-id=\"05b6ed0\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">3. \u4ee3\u7406\u6d4b\u8bd5\u5de5\u5177<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b3ef50 elementor-widget elementor-widget-code-highlight\" data-id=\"9b3ef50\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-php \">\n\t\t\t\t<code readonly=\"true\" class=\"language-php\">\n\t\t\t\t\t<xmp><?php\r\n\/**\r\n * \u4ee3\u7406\u6d4b\u8bd5\u5de5\u5177\r\n *\/\r\n\r\nclass ProxyTestTool {\r\n    \r\n    private $proxy_host = 'proxy.ipnut.com';\r\n    private $proxy_port = 28001;\r\n    private $proxy_username = 'ipnut';\r\n    private $proxy_password = '123456789';\r\n    \r\n    \/**\r\n     * \u6d4b\u8bd5SOCKS5\u4ee3\u7406\r\n     *\/\r\n    public function testSocks5Proxy() {\r\n        echo \"\u6d4b\u8bd5 SOCKS5 \u4ee3\u7406:\\n\";\r\n        \r\n        $ch = curl_init();\r\n        curl_setopt_array($ch, [\r\n            CURLOPT_URL => 'http:\/\/httpbin.org\/ip',\r\n            CURLOPT_RETURNTRANSFER => true,\r\n            CURLOPT_TIMEOUT => 15,\r\n            CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n            CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,\r\n            CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n            CURLOPT_SSL_VERIFYPEER => false\r\n        ]);\r\n        \r\n        $response = curl_exec($ch);\r\n        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n        \r\n        if (curl_error($ch)) {\r\n            echo \"\u274c SOCKS5 \u4ee3\u7406\u8fde\u63a5\u5931\u8d25: \" . curl_error($ch) . \"\\n\";\r\n        } else {\r\n            echo \"\u2705 SOCKS5 \u4ee3\u7406\u8fde\u63a5\u6210\u529f\\n\";\r\n            echo \"   \u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n            $data = json_decode($response, true);\r\n            echo \"   \u5f53\u524dIP: \" . ($data['origin'] ?? '\u672a\u77e5') . \"\\n\";\r\n        }\r\n        \r\n        curl_close($ch);\r\n    }\r\n    \r\n    \/**\r\n     * \u6d4b\u8bd5HTTP\u4ee3\u7406\r\n     *\/\r\n    public function testHttpProxy() {\r\n        echo \"\\n\u6d4b\u8bd5 HTTP \u4ee3\u7406:\\n\";\r\n        \r\n        $ch = curl_init();\r\n        curl_setopt_array($ch, [\r\n            CURLOPT_URL => 'http:\/\/httpbin.org\/ip',\r\n            CURLOPT_RETURNTRANSFER => true,\r\n            CURLOPT_TIMEOUT => 15,\r\n            CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,\r\n            CURLOPT_PROXYTYPE => CURLPROXY_HTTP,\r\n            CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,\r\n            CURLOPT_SSL_VERIFYPEER => false\r\n        ]);\r\n        \r\n        $response = curl_exec($ch);\r\n        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n        \r\n        if (curl_error($ch)) {\r\n            echo \"\u274c HTTP \u4ee3\u7406\u8fde\u63a5\u5931\u8d25: \" . curl_error($ch) . \"\\n\";\r\n        } else {\r\n            echo \"\u2705 HTTP \u4ee3\u7406\u8fde\u63a5\u6210\u529f\\n\";\r\n            echo \"   \u72b6\u6001\u7801: \" . $httpCode . \"\\n\";\r\n            $data = json_decode($response, true);\r\n            echo \"   \u5f53\u524dIP: \" . ($data['origin'] ?? '\u672a\u77e5') . \"\\n\";\r\n        }\r\n        \r\n        curl_close($ch);\r\n    }\r\n    \r\n    \/**\r\n     * \u8fd0\u884c\u6d4b\u8bd5\r\n     *\/\r\n    public function runTests() {\r\n        echo \"=== \u4ee3\u7406\u6d4b\u8bd5\u5de5\u5177 ===\\n\\n\";\r\n        \r\n        $this->testSocks5Proxy();\r\n        $this->testHttpProxy();\r\n        \r\n        echo \"\\n\u4ee3\u7406\u6d4b\u8bd5\u5b8c\u6210!\\n\";\r\n    }\r\n}\r\n\r\n\/\/ \u8fd0\u884c\u6d4b\u8bd5\u5de5\u5177\r\n$testTool = new ProxyTestTool();\r\n$testTool->runTests();\r\n?><\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-ca6a65b e-flex e-con-boxed e-con e-parent\" data-id=\"ca6a65b\" data-element_type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-3b64c01 elementor-widget elementor-widget-heading\" data-id=\"3b64c01\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">4. \u4e3b\u7a0b\u5e8f\u6587\u4ef6<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-26289fa elementor-widget elementor-widget-code-highlight\" data-id=\"26289fa\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-php \">\n\t\t\t\t<code readonly=\"true\" class=\"language-php\">\n\t\t\t\t\t<xmp><?php\r\n\/**\r\n * \u4e3b\u7a0b\u5e8f - \u4ee3\u7406\u6f14\u793a\u603b\u5165\u53e3\r\n *\/\r\n\r\n\/\/ \u5305\u542b\u6240\u6709\u7c7b\u6587\u4ef6\r\nrequire_once 'Socks5ProxyDemo.php';\r\nrequire_once 'HttpProxyDemo.php';\r\nrequire_once 'ProxyTestTool.php';\r\n\r\nclass MainProgram {\r\n    \r\n    public function run() {\r\n        echo \"PHP\u4ee3\u7406\u8fde\u63a5\u6f14\u793a\u7a0b\u5e8f\\n\";\r\n        echo \"==================\\n\\n\";\r\n        \r\n        \/\/ \u8fd0\u884c\u4ee3\u7406\u6d4b\u8bd5\u5de5\u5177\r\n        $testTool = new ProxyTestTool();\r\n        $testTool->runTests();\r\n        \r\n        echo \"\\n\" . str_repeat(\"=\", 50) . \"\\n\\n\";\r\n        \r\n        \/\/ \u8fd0\u884cSOCKS5\u6f14\u793a\r\n        $socks5Demo = new Socks5ProxyDemo();\r\n        $socks5Demo->runAll();\r\n        \r\n        echo \"\\n\" . str_repeat(\"=\", 50) . \"\\n\\n\";\r\n        \r\n        \/\/ \u8fd0\u884cHTTP\u6f14\u793a\r\n        $httpDemo = new HttpProxyDemo();\r\n        $httpDemo->runAll();\r\n        \r\n        echo \"\\n\u6240\u6709\u6f14\u793a\u5b8c\u6210!\\n\";\r\n    }\r\n}\r\n\r\n\/\/ \u8fd0\u884c\u4e3b\u7a0b\u5e8f\r\n$main = new MainProgram();\r\n$main->run();\r\n?><\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e20fefb elementor-widget elementor-widget-heading\" data-id=\"e20fefb\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">5. \u8fd0\u884c\u65b9\u5f0f\uff1a<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a203656 elementor-widget elementor-widget-code-highlight\" data-id=\"a203656\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-php \">\n\t\t\t\t<code readonly=\"true\" class=\"language-php\">\n\t\t\t\t\t<xmp>#\u6587\u4ef6\u7ed3\u6784\uff1a\n#proxy_demo\/\n#\u251c\u2500\u2500 Socks5ProxyDemo.php    # SOCKS5\u4ee3\u7406\u6f14\u793a\n#\u251c\u2500\u2500 HttpProxyDemo.php      # HTTP\u4ee3\u7406\u6f14\u793a\n#\u251c\u2500\u2500 ProxyTestTool.php      # \u4ee3\u7406\u6d4b\u8bd5\u5de5\u5177\n#\u2514\u2500\u2500 main.php              # \u4e3b\u7a0b\u5e8f\u5165\u53e3\n\n# bash\n# 1.\u5355\u72ec\u8fd0\u884cSOCKS5\u6f14\u793a\uff1a\nphp Socks5ProxyDemo.php\n\n# 2.\u5355\u72ec\u8fd0\u884cHTTP\u6f14\u793a\uff1a\nphp HttpProxyDemo.php\n\n# 3.\u8fd0\u884c\u6d4b\u8bd5\u5de5\u5177\uff1a\nphp ProxyTestTool.php\n\n# 4.\u8fd0\u884c\u5b8c\u6574\u6f14\u793a\uff1a\nphp main.php<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7PHP\u8bed\u8a00\u914d\u7f6eIPNut \u4ee3\u7406\uff1a \u8fdb [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"","ast-site-content-layout":"full-width-container","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"doc_category":[43],"doc_tag":[112,61,114,77,88],"class_list":["post-675","docs","type-docs","status-publish","hentry","doc_category-kai-fa-wen-dang","doc_tag-ipv4","doc_tag-ip","doc_tag-isp","doc_tag-static-residential-cn","doc_tag-88"],"year_month":"2026-05","word_count":40,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"IPNUT","author_nicename":"ipnut","author_url":"https:\/\/help.ipnut.com\/author\/ipnut\/"},"doc_category_info":[{"term_name":"\u5f00\u53d1\u6587\u6863","term_url":"https:\/\/help.ipnut.com\/cn\/docs\/kai-fa-wen-dang\/"}],"doc_tag_info":[{"term_name":"IPv4","term_url":"https:\/\/help.ipnut.com\/cn\/docs-tag\/ipv4\/"},{"term_name":"IP\u4ee3\u7406","term_url":"https:\/\/help.ipnut.com\/cn\/docs-tag\/ip%e4%bb%a3%e7%90%86\/"},{"term_name":"ISP","term_url":"https:\/\/help.ipnut.com\/cn\/docs-tag\/isp\/"},{"term_name":"\u9759\u6001\u4f4f\u5b85","term_url":"https:\/\/help.ipnut.com\/cn\/docs-tag\/static-residential-cn\/"},{"term_name":"\u9759\u6001\u6570\u636e\u4e2d\u5fc3","term_url":"https:\/\/help.ipnut.com\/cn\/docs-tag\/%e9%9d%99%e6%80%81%e6%95%b0%e6%8d%ae%e4%b8%ad%e5%bf%83\/"}],"lang":"cn","translations":{"cn":675,"en":818},"knowledge_base_info":[],"knowledge_base_slug":[],"pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs\/675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/comments?post=675"}],"version-history":[{"count":10,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs\/675\/revisions"}],"predecessor-version":[{"id":707,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs\/675\/revisions\/707"}],"wp:attachment":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/media?parent=675"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/doc_category?post=675"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/doc_tag?post=675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}