span style="color: #0000BB"><?php//error_reporting(0);ini_set('zlib.output_compression', 'Off');ini_set('output_handler', '');ini_set('max_execution_time', 999);//var_dump($GLOBALS["HTTP_SERVER_VARS"]); class Parser{ public $host; public $path; public $name; public $url; public $header; public $fp; public $err; public $accept_headers; public function __construct($url, $name = '') { if (!$name) { $this->name = basename($url); } else { $this->name = $name; } $url = parse_url($url); $this->host = $url['host']; $this->path = $url['path']; $this->accept_headers = $this->get_accept_headers(); } public function __destruct() { is_resource($this->fp) ? fclose($this->fp) : null; } /** * Подготовка принятых заголовков для передачи * * @return string */ private function get_accept_headers () { $headers = ''; foreach ($_SERVER as $k => $v) { $http = substr($k, 0, 5); if ($http == 'HTTP_') { $h = substr($k, 5); if ($h == 'HOST') { $headers .= 'Host: ' . $this->host . "\r\n"; } else if ($h == 'REFERER') { $headers .= 'Referer: http://' . $this->host . "\r\n"; } else if ($h == 'CONNECTION') { $headers .= "Connection: close\r\n"; } else if ($h == 'ACCEPT_ENCODING' || $h == 'TE') { // пропускаем } else { $headers .= str_replace('_', '-', ucwords(strtolower($h))) . ': ' . $v . "\r\n"; } } } return $headers; } /** * Соеденение и передача заголовков * * @return bool */ public function connect () { $this->fp = @fsockopen($this->host, 80, $errno, $errstr, 10); if (!$this->fp) { $this->err = '<h1>' . $errno . '</h1>' . "\n" . '<p>' . $errstr . '</p>'; return false; } else { fputs ($this->fp, "GET " . $this->path . " HTTP/1.0\r\n" . $this->accept_headers . "\r\n"); return true; } } /** * Получаю заголовки * * @return array */ public function get_headers () { $headers = array(); while (($b = fgets($this->fp)) !== false) { $b = trim($b); if ($b === '') break; if (substr($b, 0, 5) == 'HTTP/') { $headers['HTTP'] = $b; } else { $buf = explode(': ', $b); $headers[$buf[0]] = $buf[1]; } } return $headers; } /** * Запись файла */ public function readfile () { $starttime = microtime(1); $fp = fopen('info.txt', 'a'); fputs($fp, $this->accept_headers . "\n\n\n\n"); while (($f = fgets($this->fp)) !== false) { $len = strlen($f); $stt = microtime(1); fputs($fp, $len . ' - ' . ($stt - $starttime) . "\n"); $starttime = $stt; } }}set_time_limit(999);$file = new Parser ('http://ds.sasisa.ru/fc/upload_files/1199739600/wap_sasisa_ru_homevideo_tanya_xxx.3gp');if (!$file->connect()) exit($file->err);$headers = $file->get_headers();//var_dump($headers); exit; //header($headers['HTTP']);//header('Keep-Alive: timeout=10, max=60');//header('Connection: Keep-Alive, close');//header ("Cache-Control: None");//header('Content-Encoding: binary');//header('Content-Disposition: attachment; filename="' . $file->name . '"'); //if($headers['Content-Range']) //header('Content-Range: ' . $headers['Content-Range']); //if($headers['Accept-Ranges']) //header('Accept-Ranges: ' . $headers['Accept-Ranges']); //header('Content-Length: ' . $headers['Content-Length']); //header('Content-Type: ' . $headers['Content-Type']); $file->readfile(); |