Bug #74483 [Com]: stream_socket_client fails without hosts entry
| From: | spam2 at rhsoft dot net | Date: | Fri, 21 Apr 2017 13:30:19 +0000 |
| Subject: | Bug #74483 [Com]: stream_socket_client fails without hosts entry | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-208706@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74483&edit=1
ID: 74483
Comment by: spam2 at rhsoft dot net
Reported by: imacarthur at moditcms dot com
Summary: stream_socket_client fails without hosts entry
Status: Closed
Type: Bug
Package: Apache related
Operating System: Fedora 25
PHP Version: 7.0.18
Block user comment: N
Private report: N
New Comment:
[Unit]
Description=Apache Webserver
After=network.service systemd-networkd.service network-online.target mysqld.service
mkdir /etc/systemd/system/httpd.d/
chmod 0755 /etc/systemd/system/httpd.d/
echo "After=network.service systemd-networkd.service network-online.target">
/etc/systemd/system/httpd.d/after.conf
chmod 0644 /etc/systemd/system/httpd.d/after.conf
Previous Comments:
------------------------------------------------------------------------
[2017-04-21 13:25:44] imacarthur at moditcms dot com
My apologies. I had been following numerous threads from multiple versions of php about this issue,
claiming it was a php issue.
The solution that is working is restarting the httpd service after the machine boot settles down.
Somehow it seems that apache reads the resolv.conf before the network is up and running and
won't resolve names, but it's not consistent. Sometimes it works, others not. But so far
restarting httpd after a boot is working.
------------------------------------------------------------------------
[2017-04-20 20:54:25] daverandom@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
If you can provide more information, feel free to add it
to this bug and change the status back to "Open".
Thank you for your interest in PHP.
This appears to be an issue with your server rather than an issue with PHP.
Please user resources like stackoverflow.com and serverfault.com to resolve this issue.
------------------------------------------------------------------------
[2017-04-20 20:35:06] spam2 at rhsoft dot net
> Always works from the command line. It's only from within
> Apache I see the issue. Multiple sites [maps.googleapis.com,
> fedex.com, even google.com] have the same issue
and how is that a PHP issue?
you apache environment runs in some weird chroot and can't resolve DNS names - fix your setup
------------------------------------------------------------------------
[2017-04-20 20:28:53] imacarthur at moditcms dot com
Description:
------------
Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not
known in /home/vhosts/vitatree/test.php on line 9
Warning: stream_socket_client(): unable to connect to ssl://pilot-payflowpro.paypal.com:443
(php_network_getaddresses: getaddrinfo failed: Name or service not known) in
/home/vhosts/vitatree/test.php on line 9
errno :0 message: php_network_getaddresses: getaddrinfo failed: Name or service not known
If I add an entry in /etc/hosts for the site it works. Always works from the command line. It's
only from within Apache I see the issue. Multiple sites [maps.googleapis.com, fedex.com, even
google.com] have the same issue. The name won't resolve without an entry in /etc/hosts.
php test.php - works
wget //hostname/test.php - fails
Actual php version is 7.0.17
Linux ingagedigital.com 4.9.13-200.fc25.x86_64 #1 SMP Mon Feb 27 16:48:42 UTC 2017 x86_64
Apache/2.4.25 (Fedora) OpenSSL/1.0.2k-fips PHP/7.0.17 mod_perl/2.0.10 Perl/v5.24.1
Test script:
---------------
<?php
$context_opts = array();
$context = stream_context_create($context_opts);
$fp = stream_socket_client(
"ssl://pilot-payflowpro.paypal.com:443",
$errno,
$errmsg,
1000,
STREAM_CLIENT_CONNECT,
$context);
echo "errno :".$errno." message: ".$errmsg.PHP_EOL;
?>
Expected result:
----------------
errno :0 message:
Actual result:
--------------
Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not
known in /home/vhosts/vitatree/test.php on line 9
Warning: stream_socket_client(): unable to connect to ssl://pilot-payflowpro.paypal.com:443
(php_network_getaddresses: getaddrinfo failed: Name or service not known) in
/home/vhosts/vitatree/test.php on line 9
errno :0 message: php_network_getaddresses: getaddrinfo failed: Name or service not known
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74483&edit=1