|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-03-05 17:59 UTC] scott at abcoa dot com
Description:
------------
I had no trouble with the fsockopen() until I upgraded to PHP 4.3.4. My last working version was 4.2.3 before the upgrade. It sure look like a fsockopen() issue. Enclosed below is the source code that produce the same error result with both the Apache/Browser and the Shell Environment. I tried variety of URL Address and still get the same result, like www.google.com, www.cnn.com, www.php.net, etc... Been trying different ways with the scripts, machine and network and yet get the same result. I tried with and without the "tcp:\\" and still get the same result. (One more thing, could error 66 meant 6 with an one digit, not two??)
Reproduce code:
---------------
<?
//fsockopen("tcp:\\www.google.com",80,$errno,$errstr,30);
fsockopen("www.google.com",80,$errno,$errstr,30);
echo "\n\n";
echo $errno."\n\n";
echo $errstr."\n\n";
?>
Expected result:
----------------
Should expect to see an successful connection to www.google.com
Actual result:
--------------
Warning: fsockopen() [http://www.php.net/function.fsockopen]: php_hostconnect: connect failed in <<file path omitted by me>> on line 5
Warning: fsockopen() [http://www.php.net/function.fsockopen]: unable to connect to www.google.com:80 in <<file path omitted by me>> on line 5
66
Addr family not supported by protocol
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 18:00:01 2025 UTC |
I'm also concerned that you may not actually be testing against 4.3... One of the error messages you noted in your original report "php_hostconnect: connect failed in ..." only appears in PHP >prior< to version 4.3.0. As of the 4.3 branch that message contains noticably different text. This discrepency doesn't necessary speak to the fact that the error is occuring. But it raises a question as to whether there are "lingering ghosts" of the prior version. Perhaps creating a conflict with 4.3 which leads to the emergence of the error. Can you conirm that (after the copious number of recompiles you've been asked for) you're still getting that specific error message in your output? It'd also be interresting to see if the sockets extension behaves in the same way: <?php $socket = socket_create(AF_INET, SOCK_STREAM, 0); var_dump($socket); var_dump(socket_connect($socket, 'www.google.com', 80)); ?> or (for a slight variation: <?php $socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp")); var_dump($socket); var_dump(socket_connect($socket, 'www.google.com', 80)); ?> Of course, you'll need to ./configure --enable-sockets in order to try these tests.In response to sniper@php.net's comment... Removed the config.cache, rebuild PHP with "./configure --disable-all --disable-cgi", ran the test script using CLI and still get this same error message. --snip-- !#/usr/local/bin/php Warning: fsockopen(): unable to connect to www.google.com:80 in <<file path omitted by me>> on line 6 66 Addr family not supported by protocol --snip-- It had been observed that during most of those compilation using "make" I saw this warning messages. I don't think this is related to socket stuffs but thought you may would to know. -snip-- gcc -Iext/standard/ -I/usr/local/src3/php4-STABLE-200403081230/ext/standard/ -DPHP_ATOM_INC -I/usr/local/src3/php4-STABLE-200403081230/include -I/usr/local/src3/php4-STABLE-200403081230/main -I/usr/local/src3/php4-STABLE-200403081230 -I/usr/local/src3/php4-STABLE-200403081230/Zend -I/usr/local/src3/php4-STABLE-200403081230/TSRM -O2 -c /usr/local/src3/php4-STABLE-200403081230/ext/standard/file.c -o ext/standard/file.o && echo > ext/standard/file.lo /usr/local/src3/php4-STABLE-200403081230/ext/standard/file.c: In function `zif_fgetcsv': /usr/local/src3/php4-STABLE-200403081230/ext/standard/file.c:2308: warning: passing arg 4 of `_php_stream_get_line' from incompatible pointer type /usr/local/src3/php4-STABLE-200403081230/ext/standard/file.c:2373: warning: passing arg 4 of `_php_stream_get_line' from incompatible pointer type gcc -Iext/standard/ -I/usr/local/src3/php4-STABLE-200403081230/ext/standard/ -DPHP_ATOM_INC -I/usr/local/src3/php4-STABLE-200403081230/include -I/usr/local/src3/php4-STABLE-200403081230/main -I/usr/local/src3/php4-STABLE-200403081230 -I/usr/local/src3/php4-STABLE-200403081230/Zend -I/usr/local/src3/php4-STABLE-200403081230/TSRM -O2 -c /usr/local/src3/php4-STABLE-200403081230/ext/standard/filestat.c -o ext/standard/filestat.o && echo > ext/standard/filestat.lo --snip-- In response to pollita@php.net's comment... >>whether there are "lingering ghosts" of >>the prior version. Could be, I wouldn't deny it. The error message you saw in the original report was the output from the website. The ./configure command line was --snip-- ./configure --with-apache=../apache_1.3.27 --with-ibm-db2=/usr/lpp/db2_06_01 --with-openssl --with-mcrypt --with-curl --without-mysql --enable-track-vars --snip-- Since then, I found that I can produce this error through the CLI, so I did away with the website and use CLI instead because it is alot quicker to recompile than it is with PHP and webserver. Since then there have been a numerous recompiling as instructed by this bug report. >>Can you confirm that you're still getting that >>specific error message in your output? I can confirm that the "php_hostconnect" does not exist anymore. I am unable to reproduce this "php_hostconnect" error this time. I don't remember what I did to make this happen. All I know is that it was as result of fiddling around with the wording in the fsockopen()'s parameter arguements to find out what work and what doesn't. >>Of course, you'll need to ./configure --enable-sockets >>in order to try these tests. Okay, did the favor and recompile it with "./configure --enable-sockets" configure line. Saw two warning messages, one from above and other is --snip-- gcc -Iext/sockets/ -I/usr/local/src3/php4-STABLE-200403081230/ext/sockets/ -DPHP_ATOM_INC -I/usr/local/src3/php4-STABLE-200403081230/include -I/usr/local/src3/php4-STABLE-200403081230/main -I/usr/local/src3/php4-STABLE-200403081230 -I/usr/local/src3/php4-STABLE-200403081230/Zend -I/usr/local/src3/php4-STABLE-200403081230/ext/xml/expat -I/usr/local/src3/php4-STABLE-200403081230/TSRM -O2 -c /usr/local/src3/php4-STABLE-200403081230/ext/sockets/sockets.c -o ext/sockets/sockets.o && echo > ext/sockets/sockets.lo /usr/local/src3/php4-STABLE-200403081230/ext/sockets/sockets.c: In function `php_strerror': /usr/local/src3/php4-STABLE-200403081230/ext/sockets/sockets.c:350: warning: assignment makes pointer from integer without a cast --snip-- Ran the sample test of the codes you posted, I included both by the way. Ran it through the CLI and here's the response I got... --snip-- Content-type: text/html X-Powered-By: PHP/4.3.5RC4-dev !#/usr/local/bin/php resource(1) of type (Socket) bool(true) resource(2) of type (Socket) bool(true) --snip--Sorry, I wanted you to run a test with fsockopen(), not the socket_* extension. (Believe it or not they're completely different implementations even though they do the same thing) <?php $fp = fsockopen('www.exmaple.com', 80); ?> Please run that one against the version you've already patched and compiled.Here's the response I got... It's also the same with the host, "www.example.com" instead of "www.google.com". --snip-- Content-type: text/html X-Powered-By: PHP/4.3.5RC4-dev !#/usr/local/bin/php getaddresses GETADDRINFO method defaulting to AF_INET(2) hints.ai_family = 0 got result sai->ai_family = 2 returning from getaddresses: n = 1 php_network_getaddresses returned 1 Creating socket of type 0 (AF_INET = 2) socket() returned: -1 <br /> <b>Warning</b>: fsockopen(): unable to connect to www.google.com:80 in <b>/home/website/emarket/test_fsockopen_shell.sh</b> on line <b>6</b><br /> 66 Addr family not supported by protocol --snip--