note 94831 added to function.fopen

From: Date: Fri, 27 Nov 2009 11:28:58 +0000
Subject: note 94831 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-163326@lists.php.net to get a copy of this message
Hello all. I have had trouble getting files through proxy, and the solution posted above only works if the requested file is also hosted on the proxy server (which is quite unlikely). so I've put together the following functions pfopen & preadfile. they quite work like the replaced fopen & readfile, and will resort to them if no proxy is provided :) function preadfile($_url, $_proxy_name = null, $_proxy_port = 4480){ if(is_null($_proxy_name) || LOCAL_TEST){ return readfile($_url); }else{ $proxy_cont = ''; $proxy_fp = pfopen($_url, $_proxy_name, $_proxy_port); 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); echo $proxy_cont; return count($proxy_cont); } } function pfopen($_url, $_proxy_name = null, $_proxy_port = 4480) { if(is_null($_proxy_name) || LOCAL_TEST){ return fopen($_url); }else{ $proxy_fp = fsockopen($_proxy_name, $_proxy_port); if (!$proxy_fp) return false; $host= substr($_url, 7); $host = substr($bucket, 0, strpos($host, "/")); $request = "GET $_url HTTP/1.0\r\nHost:$host\r\n\r\n"; fputs($proxy_fp, $request); return $proxy_fp; } } ---- Server IP: 195.221.21.36 Probable Submitter: 193.253.243.106 ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- https://master.php.net/note/edit/94831 Del: integrated -- https://master.php.net/note/delete/94831/integrated Del: useless -- https://master.php.net/note/delete/94831/useless Del: bad code -- https://master.php.net/note/delete/94831/bad+code Del: spam -- https://master.php.net/note/delete/94831/spam Del: non-english -- https://master.php.net/note/delete/94831/non-english Del: in docs -- https://master.php.net/note/delete/94831/in+docs Del: other reasons-- https://master.php.net/note/delete/94831 Reject -- https://master.php.net/note/reject/94831 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163326) next »