PHP Guzzle 5: Cannot handle URL with PORT number in it

余生颓废 提交于 2019-12-10 21:42:10

问题


I am using the latest version of guzzle.

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

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

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());

I get the following error:

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

When I do the same but omit the PORT:

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

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.

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.


回答1:


For all those banging their heads against the wall due to the

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

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).

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.

Open:

nano /etc/selinux/config

Locate:

SELINUX=enforcing

Change:

SELINUX=disabled

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



来源:https://stackoverflow.com/questions/29017526/php-guzzle-5-cannot-handle-url-with-port-number-in-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!