Re: fsockopen: fetching url

From: Date: Fri, 11 Feb 2005 16:40:07 +0000
Subject: Re: fsockopen: fetching url
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-208532@lists.php.net to get a copy of this message
branimir.topic@swing-consulting.hr wrote: > > I'm using code below to fetch content from the url. > This code was worked properly on two servers I tested but it want worked > on > the > designated one, so after getting error message I figure it out it may > be php.ini settings limitation > > ---------------------------------------------------------------------------------------------------------------- > "The server encountered an internal error or misconfiguration and was > unable to complete your request." > "Additionally, a 404 Not Found error was encountered while trying to use > an > ErrorDocument to handle the request." Do *ANY* PHP scripts work on that server? <?php phpinfo();?> is a good example to try. ---------------------------------------------------------------------------------------------------------------- > > > So here's the settings I found as possible reason for limitation on code > execution. > > ---------------------------------------------------------------------------------------------------------------- > disable_functions: readfile, system, passthru, shell_exec, shell_exec, > system, execreadfile, system, passthru, shell_exec, shell_exec, system, > exec Are you using any of those functions?... I don't see them in your code. ---------------------------------------------------------------------------------------------------------------- > Does anybody hava any tip how to workarround on this? > > > CODE > > ---------------------------------------------------------------------------------------------------------------- > function fetchURL( $url ) { > $url_parsed = parse_url($url); > $host = isset($url_parsed["host"]) ? $url_parsed["host"]: ""; > $port = isset($url_parsed["port"]) ? $url_parsed["port"]: 0; > if ($port==0) > $port = 80; > $path = $url_parsed["path"]; > > $query = isset($url_parsed["query"]) ? $url_parsed["query"]: > ""; > > if ($query != "") > $path .= "?" . $query; > > $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"; > > $fp = fsockopen($host, $port, $errno, $errstr, 30); > > fwrite($fp, $out); > $body = false; > $in = ""; > while (!feof($fp)) { > $s = fgets($fp, 1024); > if ( $body ) > $in .= $s; > if ( $s == "\r\n" ) > $body = true; > } > > fclose($fp); > > return $in; > } -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#208532) next »