gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:06:40 28 4
gpt4 key购买 nike

由于 fsockopen 函数和 HEAD 命令,我有一个 PHP 运行代码询问远程 mp4 文件的文件大小。

现在,我需要将此代码移动到代理后面的其他服务器,这是通过新代理并继续使用 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;
}

最佳答案

没有代理:

<?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 with proxy

关于php - 我需要通过代理,(从正在运行的 fsockopen 代码获取远程视频文件的大小),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7285789/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com