Skip to content

Instantly share code, notes, and snippets.

@antimatter15
Created January 10, 2010 01:00
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save antimatter15/273254 to your computer and use it in GitHub Desktop.
Save antimatter15/273254 to your computer and use it in GitHub Desktop.
<?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