问题
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