我需要通过代理,(从运行的fsockopen代码获取远程视频文件的大小)

Fab*_*umi 4 php proxy fsockopen

我有一个运行PHP代码,问一个远程的MP4文件的文件大小,多亏了的fsockopen功能和HEAD命令.

现在,我需要将此代码移动到代理后面的其他服务器,这是通过该新代理的最佳方法,并继续使用fsockopen?我真的被卡住了.我不能隧道或处理两个插座.

有任何想法吗?谢谢你的帮助和时间.

private function filesize_remote($remotefile, $timeout=10) {
       $size = false;
       $url = parse_url($remotefile);

       if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] : 80), $errno, $errstr, $timeout)) {
          fwrite($fp, 'HEAD '.@$url['path'].@$url['query'].' HTTP/1.0'."\r\n".'Host: '.@$url['host']."\r\n\r\n");
          while (!feof($fp)) {
             $headerline = fgets($fp, 4096);
             if (preg_match('/^Content-Length: (.*)/', $headerline, $matches)) {
                $size = intval($matches[1]);
                break;
             }
          }
          fclose ($fp);
       }

       return $size;  
    } 
Run Code Online (Sandbox Code Playgroud)

gla*_*kou 9

没有代理:

<?php
$fp = fsockopen("www.wahoo.com",80);

fputs($fp, "GET <a href=\"http://www.yahoo.com/\" "
  ."title=\"http://www.yahoo.com/\">http://www.yahoo.com/</a> HTTP/1.0\r\n\r\n");

$data="";
while (!feof($fp)) $data.=fgets($fp,64000);
fclose($fp);

print $data;
?>
Run Code Online (Sandbox Code Playgroud)

使用代理:

<?php
$ip = "1.2.3.4"; // proxy IP, change this according to your proxy setting
$port = 1234; // proxy port, change this according to your proxy setting

$fp = fsockopen($ip,$port); // connect to proxy
fputs($fp, "GET <a href=\"http://www.yahoo.com/\"   "
  . "title=\"http://www.yahoo.com/\">http://www.yahoo.com/</a>  "
  . "HTTP/1.0\r\nHost:www.yahoo.com:80\r\n\r\n");

$data="";
while (!feof($fp)) $data.=fgets($fp,64000);
fclose($fp);

print $data;
?>
Run Code Online (Sandbox Code Playgroud)

使用代理和身份验证:

<?php
$ip = "1.2.3.4"; // proxy IP, change this according to your proxy setting
$port = 1234; // proxy port, change this according to your proxy setting

$fp = fsockopen($ip,$port); // connect to proxy

$login = "Alexander"; // login name
$passwd = "kiss me"; // password

fputs($fp, "GET <a href=\"http://www.yahoo.com/\" "
 . "title=\"http://www.yahoo.com/\">http://www.yahoo.com/</a> HTTP/1.1\r\n"
 . "Host:www.yahoo.com:80\r\n"
 . "Proxy-Authorization: Basic ".base64_encode("$login:$passwd") ."\r\n\r\n");

$data="";
while (!feof($fp)) $data.=fgets($fp,64000);
fclose($fp);

//12314
print $data;
?>
Run Code Online (Sandbox Code Playgroud)

看这里:Fsockopen与代理