php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74483 stream_socket_client fails without hosts entry
Submitted: 2017-04-20 20:28 UTC Modified: 2017-04-21 13:25 UTC
From: imacarthur at moditcms dot com Assigned:
Status: Closed Package: Apache related
PHP Version: 7.0.18 OS: Fedora 25
Private report: No CVE-ID: None
 [2017-04-20 20:28 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-20 20:35 UTC] 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:54 UTC] daverandom@php.net
-Status: Open +Status: Feedback
 [2017-04-20 20:54 UTC] 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-21 13:25 UTC] imacarthur at moditcms dot com
-Status: Feedback +Status: Closed
 [2017-04-21 13:25 UTC] 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-21 13:30 UTC] spam2 at rhsoft dot net
[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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC