I need to go through a proxy server (from the fsockopen executable, which gets the size from the remote video file)

I have PHP code that sets the file size of a remote mp4 file, thanks to the fsockopen and HEAD functions.

Now I need to move this code to another server behind the proxy server that is best suited to go through this new proxy server and continue to use fsockopen? I'm really stuck. I cannot tunnel or process two sockets.

Any ideas? Thanks for the 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; } 
+4
source share
1 answer

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

Take a look here: Fsockopen with proxy server

+9
source

All Articles