This function allows you to retrieve a remote file via a web proxy in php. It replaced the usage of “fopen” and “fgets” in the modified script I snipped this from, which was an atom feed reader. In situations where outgoing connections are necessarily proxied, you can substitute the following:
function proxy_fopen($proxy,$port,$url) {
$proxy_cont = '';
$proxy_fp = fsockopen($proxy, $port);
if (!$proxy_fp) {return false;}
fputs($proxy_fp, "GET $proxy_url HTTP/1.0\r\nHost: $proxy_name\r\n\r\n");
while(!feof($proxy_fp)) {$proxy_cont .= fread($proxy_fp,4096);}
fclose($proxy_fp);
$proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);
return $proxy_cont;
}
It is called, for instance, as:
$blah = proxy_fopen("192.168.1.10","8080",“http://www.google.com?q=cancer+class+action”);












