Created
January 10, 2010 01:00
-
-
Save antimatter15/273254 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//php streaming proxy | |
header('Access-Control: allow <*>'); //xdomain ajax ftw | |
set_time_limit(24*3600); | |
$fp = fsockopen("192.168.1.149", 80, $errno, $errstr, 30); | |
if (!$fp) { | |
echo "$errstr ($errno)<br />\n"; | |
} else { | |
$out = "GET /slow.php HTTP/1.1\r\n"; | |
$out .= "Host: 192.168.1.149\r\n"; | |
$out .= "Connection: Close\r\n\r\n"; | |
$headers = true; | |
$remain = 0; | |
fwrite($fp, $out); | |
while (!feof($fp)) { | |
if($headers == true){ | |
$line = fgets($fp); | |
if($line == "\r\n"){ | |
$headers = false; | |
}else{ | |
if(strpos($line, "HTTP/") === false){ | |
$exp = explode(":",$line); | |
$n = strtolower(trim($exp[0])); | |
$ignore = explode(",","connection,content-encoding,transfer-encoding,access-control"); | |
if(!in_array($n, $ignore)){ | |
header(trim($line)); | |
} | |
} | |
} | |
}else{ | |
if($remain == 0){ | |
$line = fgets($fp); | |
$remain = hexdec(trim($line)); | |
}else{ | |
$buf = fread($fp, $remain); | |
echo $buf; | |
$remain = 0; | |
} | |
flush(); | |
} | |
} | |
fclose($fp); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment