PHP Guzzle 5:无法处理其中带有端口号的URL [英] PHP Guzzle 5: Cannot handle URL with PORT number in it

查看:363
本文介绍了PHP Guzzle 5:无法处理其中带有端口号的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新版本的guzzle.

I am using the latest version of guzzle.

(from composer.json)
"guzzlehttp/guzzle": "~5" 

(from composer.lock)
"name": "guzzlehttp/guzzle",
"version": "5.2.0",

当我尝试使用包含端口号的URL请求(GET或POST)时:

When I attempt to request (GET or POST) with a URL that contains a PORT number:

$response = $client->get('http://www.hostdnshere.com:8888', array());

我收到以下错误:

string(68) "cURL error 7: Failed to connect to 000.000.000.000: Permission denied"

当我这样做但忽略PORT时:

When I do the same but omit the PORT:

$response = $client->get('http://www.hostdnshere.com', array());

请求成功,没有问题.我已经搜索了文档并在Google上搜索了Web,但是由于无法包含主机,因此无法找到如何设置主机的端口.

The request succeeds without issue. I have searched the documentation and Googled the web but cannot find out how to set the port for the host since it cannot be included.

此外,无论是否有PORT,我都使用发送请求的服务器形式上的cURL对cURL进行了全部测试,无论如何,它都像魅力一样起作用,因此我知道它与服务器,DNS,代理无关或端口.

Additionally, I have tested it all using cURL on the server form which the requests are being sent, with and without the PORT, works like a charm no matter what so I know its not an issue with the Server, DNS, Proxies, or PORTS.

推荐答案

对于所有由于

"cURL error 7: Failed to connect to 000.000.000.000: Permission denied"

错误,全部归结为"SELINUX".没错,以任何编程语言编写的任何cURL包装器都可能受到以下事实的影响:当将'SELINUX'设置为'enforceing'时,就会遇到针对其中具有非标准PORT的URL执行cURL的问题(即my.domain.com:8888).

error, it all boils down to 'SELINUX'. That is right, any cURL wrapper written in any programming language can be affected by the fact that when 'SELINUX' is set to 'enforcing' it takes issue with cURL being executed against a URL that has a non-standard PORT in it (i.e. my.domain.com:8888).

如果您希望在URL中使用非标准PORTS,建议仅用于本地开发,请将"SELINUX"设置为"disabled".生产中的正确解决方案是使用不带PORT的干净URL,以使"SELINUX"保持启用状态.

Recommended for local development only, if you wish to use non-standard PORTS in your URL's, is to set 'SELINUX' to 'disabled'. The proper solution in production will be to use clean URLs without PORTs in them in order to leave 'SELINUX' enabled.

打开:

nano /etc/selinux/config

查找:

SELINUX=enforcing

更改:

SELINUX=disabled

由于默认情况下'SELINUX'设置为'enforcing',因此使用CentOS的用户很可能会遇到此问题.

Those using CentOS will most likely be running into this issue since 'SELINUX' is set to 'enforcing' by default.

这篇关于PHP Guzzle 5:无法处理其中带有端口号的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆