我想将 GuzzleHttp 与 Socks5 代理一起使用
I want use GuzzleHttp with Socks5 proxy
我想做什么
我想将 GuzzleHttp
与 Socks5 proxy
一起使用。
问题
它不适用于 Linux。
它在 Windows.
上成功运行
(与 Linux 相同的程序)
$ php index.php
PHP Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: Connection refused for URI https://api.ipify.org in /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:311
Stack trace:
#0 /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(230): GuzzleHttp\Handler\StreamHandler->GuzzleHttp\Handler\{closure}()
#1 /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(322): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure))
#2 /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(58): GuzzleHttp\Handler\StreamHandler->createStream(Object(GuzzleHttp\Psr7\Request), Array)
#3 /root/test/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /root/test/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#5 /root/test/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::Gu in /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php on line 72
计划
composer require guzzlehttp/guzzle
composer.json
{
"require": {
"guzzlehttp/guzzle": "^7.2"
}
}
index.php
<?php
require('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$url = 'https://api.ipify.org';
$response = $client->get($url, [
'proxy' => "socks5://10.0.0.2:8080",
'timeout' => 60, // 60 second
'verify' => false
]);
var_dump($response->getBody()->getContents());
我尝试了什么 1
'proxy' => "socks5h://10.0.0.2:8080"
对结果没有影响。
参考:https://github.com/guzzle/guzzle/issues/1484#issuecomment-306724234
我尝试了什么 2
'proxy' => "tcp://10.0.0.2:8080"
对结果没有影响。
参考:https://github.com/guzzle/guzzle/issues/1484#issue-157978804
测试环境(代理服务器)
https://pypi.org/project/pproxy/
$ pproxy -l socks5://0.0.0.0:8080
测试环境(PHP)
Ubuntu 20.04.1 LTS
+ php 7.3.24-3
不工作
Ubuntu 20.04.1 LTS(WSL)
+ php 7.4.3
不工作
Windows 10 1903 64bit
+ php 7.2.12
工作成功
如何解决
只需安装php-curl
apt install php7.3-curl
之前
$ php -i | grep cURL
(No output)
之后
$ php -i | grep cURL
cURL support => enabled
cURL Information => 7.68.0
运行 节目 Linux
工作成功
$ php index.php
string(15) "xxx.xxx.xxx.x"
我想做什么
我想将 GuzzleHttp
与 Socks5 proxy
一起使用。
问题
它不适用于 Linux。
它在 Windows.
上成功运行
(与 Linux 相同的程序)
$ php index.php
PHP Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: Connection refused for URI https://api.ipify.org in /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:311
Stack trace:
#0 /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(230): GuzzleHttp\Handler\StreamHandler->GuzzleHttp\Handler\{closure}()
#1 /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(322): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure))
#2 /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(58): GuzzleHttp\Handler\StreamHandler->createStream(Object(GuzzleHttp\Psr7\Request), Array)
#3 /root/test/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /root/test/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#5 /root/test/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::Gu in /root/test/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php on line 72
计划
composer require guzzlehttp/guzzle
composer.json
{
"require": {
"guzzlehttp/guzzle": "^7.2"
}
}
index.php
<?php
require('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$url = 'https://api.ipify.org';
$response = $client->get($url, [
'proxy' => "socks5://10.0.0.2:8080",
'timeout' => 60, // 60 second
'verify' => false
]);
var_dump($response->getBody()->getContents());
我尝试了什么 1
'proxy' => "socks5h://10.0.0.2:8080"
对结果没有影响。
参考:https://github.com/guzzle/guzzle/issues/1484#issuecomment-306724234
我尝试了什么 2
'proxy' => "tcp://10.0.0.2:8080"
对结果没有影响。
参考:https://github.com/guzzle/guzzle/issues/1484#issue-157978804
测试环境(代理服务器)
https://pypi.org/project/pproxy/
$ pproxy -l socks5://0.0.0.0:8080
测试环境(PHP)
Ubuntu 20.04.1 LTS
+php 7.3.24-3
不工作Ubuntu 20.04.1 LTS(WSL)
+php 7.4.3
不工作Windows 10 1903 64bit
+php 7.2.12
工作成功
如何解决
只需安装php-curl
apt install php7.3-curl
之前
$ php -i | grep cURL
(No output)
之后
$ php -i | grep cURL
cURL support => enabled
cURL Information => 7.68.0
运行 节目 Linux
工作成功
$ php index.php
string(15) "xxx.xxx.xxx.x"