PHP 4.0 Bug #7880 Updated: PHP_URL_FOPEN doesn't work

From: Date: Sun, 31 Dec 2000 01:52:24 +0000
Subject: PHP 4.0 Bug #7880 Updated: PHP_URL_FOPEN doesn't work
Groups: php.dev 
Request: Send a blank email to php-dev+get-42732@lists.php.net to get a copy of this message
ID: 7880 User Update by: Alan@Halachmi.net Status: Closed Bug Type: *URL Functions Description: PHP_URL_FOPEN doesn't work Ok - I seem to have tracked this down. I added debug statements throughout PHP to see exactly where it was failing, and found that it is happening in: php_network_getaddresses in main/network.c. Basically, in php_fopen_url_wrap_http in ext/standard/http_fopen_wrapper.c, I modified the function to let me know where it was bailing: *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0); if (*socketd == -1) { php_error(E_WARNING, "php_hostconnect failed"); SOCK_FCLOSE(*socketd); *socketd = 0; free_url(resource); return NULL; } It does get to that php_error message, and so after looking through php_hostconnect, I found that our problem was a failed lookup in php_network_getaddresses. Here is my slightly modified code that prints out an error message when getaddrinfo fails: static int php_network_getaddresses(const char *host, struct sockaddr ***sal) { int err; struct sockaddr **sap; if (host != NULL) { #ifdef HAVE_GETADDRINFO struct addrinfo hints, *res, *sai; int n; memset( &hints, '\0', sizeof(hints) ); hints.ai_family = AF_UNSPEC; if ((err = getaddrinfo(host, NULL, &hints, &res))) { php_error(E_WARNING, "getaddrinfo failed for host: %s with error: %d", host, err); php_error(E_WARNING, gai_strerror(err)); return -1; } I took a look at php 4.0.2 (which is working fine for us), and saw that it doesn't use getaddrinfo for hostname lookups, it uses the gethostbyname function. I'm not familiar enough with the getaddrinfo call to tell you if it is failing because of a bug in Solaris, a problem in our system configuration, or if it is a problem with the php source. I have created two testpages that are failing for us, one with a numeric IP address and another with a hostname that must be resolved. You can view them here: Use of the "file" function on a numeric address: http://pkw.devilnet.duke.edu/testweather.php Use of the "file" function on a hostname that must be resolved: http://dev.dspconline.org/scripts/update_weather.php I hope this helps. Previous Comments: --------------------------------------------------------------------------- [2000-12-30 19:55:06] sniper@php.net No feedback. Reopen if this really doesn't work with correct url. --Jani --------------------------------------------------------------------------- [2000-11-20 11:45:08] jason@php.net Ya you should be looking up index.php as hholzgra suggests, but in looking at your truss output, It is behaving as if url wrappers was compiled out. Can you try this test? 1. Lets verify the source is compiled correctly. add --enable-debug to your php configure. a. Remake and make sure that gcc is being called with -g. b. do a gdb httpd c. run -X d. hit ctrl-c (it might take a while to catch) e. break php_fopen_wrapper f. cont g. open your test-script while its waiting h. it should break when it trys to make the file request i. hit n to step to the next line of code j. see if it ever hits if(!(options & IGNORE_URL)){ k. if url wrappers is not compiled you would get if (options & USE_PATH........ instead --------------------------------------------------------------------------- [2000-11-20 10:22:12] hholzgra@php.net ooops, looks like this was to early in the morning :( but it might still be of interest what the output and error messages look like if you take your code snippet and just replace the '$fp=file($url)' line with '$fp=fopen($url,"r")' it seems like file() fails to open the URL but still tries to read from the file handle that is not valid in this case, so that 'bad file number' is reported instead of the real cause if failure ... PS: i don't think this is realy related to it, but www.php.net/index.html does not exist. trying to GET it will result in a 404 status and an error page showing some search results, you should try www.php.net/index.php instead, just to be sure ... --------------------------------------------------------------------------- [2000-11-20 09:54:13] jason@php.net Actually he is using the correct usage. File takes a string calls fopen-wrappers to open a fp, and then returns an array Alan, I will see If I can reproduce your findings -Jason --------------------------------------------------------------------------- [2000-11-20 07:01:04] hholzgra@php.net $url = "http://www.php.net/index.html"; $fp = file($url); is simply wrong usage, try $url = "http://www.php.net/index.html"; $fp = fopen($url,"r"); $file_contents = file($fp); instead --------------------------------------------------------------------------- The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online. Full Bug description available at: http://bugs.php.net/?id=7880

« previous php.dev (#42732) next »