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

发布于 2024-12-02 23:14:44 字数 864 浏览 1 评论 0原文

我有一个 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;  
    } 

I've a PHP running code that ask the file size of a remote mp4 file, thanks to a fsockopen function and HEAD command.

Now, i need to move this code to other server behind a proxy, which is the best approach to go through that new proxy, and continue using fsockopen? I'm really stuck. I can't tunnel or handle two sockets.

Any ideas? thanks for your help and time.

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;  
    } 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拒绝两难 2024-12-09 23:14:44

没有代理:

<?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;
?>

使用代理:

<?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;
?>

使用代理和身份验证:

<?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;
?>

看这里: 带代理的 Fsockopen

Without proxy:

<?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;
?>

With proxy:

<?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;
?>

With proxy and authentication:

<?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;
?>

Look here: Fsockopen with proxy

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文