On 6/22/07, Ray <ray@xxxxxxxxxxxxx> wrote:
hello, I'm having some problems with fsockopen and was hopping for some help. I try to connect to a host via fsockopen and I get "getaddrinfo failed" errors, but if I try fsockopen with google, everything works. sample test code $fp=fsockopen('apps.subname.domain.com/xml_2.4/xml.php',80,$errno, $errstr); var_dump($errno); var_dump($errstr); $fp=fsockopen("000.00.00.000/xml_2.4/xml.php",80,$errno, $errstr); var_dump($errno); var_dump($errstr); $fp=fsockopen('www.google.ca',80,$errno, $errstr); var_dump($errno); var_dump($errstr); (sorry for sanitizing, not my choice.) I can ping the host from the server, and going to this site in a browser gives the expected output. Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in /usr/local/www/apache22/data/index.php on line 119 Warning: fsockopen() [function.fsockopen]: unable to connect to apps.subname.domain.com/xml_2.4/xml.php:80 (Unknown error) in /usr/local/www/apache22/data/index.php on line 119 int(0) string(0) "" [note no error for google. should be here] Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in /usr/local/www/apache22/data/index.php on line 122 Warning: fsockopen() [function.fsockopen]: unable to connect to 000.00.00.000/xml_2.4/xml.php:80 (Unknown error) in /usr/local/www/apache22/data/index.php on line 122 int(0) string(0) "" int(0) string(0) ""
With fsockopen you connect to a host, not to the host with full path... This would work fine: $fp=fsockopen('apps.subname.domain.com',80,$errno, $errstr); var_dump($errno); var_dump($errstr); Now you probably want to get that file, so you should do a fwrite: fwrite($fp,"GET /xml_2.4/xml.php HTTP/1.1\r\nHost: apps.subname.domain.com\r\n\r\n"); *note: All above should be on one single line Then, after you made a request, you can get the data with fread: $data = fread($fp,102400); // 100KB of data max This returns the page, including the headers! If you only want data, you're better off using file_get_contents function, like this: $data = file_get_contents("'apps.subname.domain.com/xml_2.4/xml.php"); Hope this helps ;) Tijnema -- Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php