Skip to content

Commit cb0c277

Browse files
committed
PHP Proxy Optim. #65
1 parent 538be1e commit cb0c277

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
2.9.2
1+
2.9.3
22
2.9
33
2

php/classes/Helper.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,27 @@ class Helper {
2121
* @param $link the url to follow its redirects
2222
*/
2323
public static function getFinalUrl( string $link ) : string {
24-
$ch = curl_init();
25-
26-
curl_setopt($ch, CURLOPT_URL, $link);
27-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
28-
curl_setopt($ch, CURLOPT_NOBODY, true);
29-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
30-
31-
if( curl_exec($ch) ){
32-
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
33-
} else{
34-
$url = $link;
24+
if( function_exists('curl_init') ){
25+
$ch = curl_init();
26+
27+
curl_setopt($ch, CURLOPT_URL, $link);
28+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
29+
curl_setopt($ch, CURLOPT_NOBODY, true);
30+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
31+
32+
if( curl_exec($ch) ){
33+
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
34+
} else{
35+
$url = $link;
36+
}
37+
38+
curl_close($ch);
39+
40+
return $url;
3541
}
3642

37-
curl_close($ch);
38-
39-
return $url;
43+
error_log("Warning: Please install CURL for better support of Proxy");
44+
return $link;
4045
}
4146

4247
public static function checkFilename( $n ) : bool {

php/classes/SimpleProxy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public static function open( $url ){
114114

115115
if( $f !== false ){
116116
self::sendHeader($header);
117+
// unset the execution limit (long time proxying)
118+
set_time_limit(0);
119+
// while something to proxy and still a client
117120
while(!feof($f) && !connection_aborted() ){
118121
echo fread($f, 128);
119122
flush();

php/stream.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@
5555
if( !empty($url) && filter_var( $url, FILTER_VALIDATE_URL) !== false ){
5656
$url = filter_var($url, FILTER_SANITIZE_URL); //clean url
5757

58+
// the proxy does not support redirects!, so do them before
59+
$url = Helper::getFinalUrl($url);
60+
5861
if(!DOCKER_MODE){ // use a PHP based proxy
5962
SimpleProxy::open( $url );
6063
die();
6164
}
6265

63-
// the proxy does not support redirects!, so do them before
64-
$url = Helper::getFinalUrl($url);
65-
66-
6766
// get hostname and url parts before and after
6867
$matches = array();
6968
$matchok = preg_match( '/^(https?:\/\/)([^\/]+\.?[a-zA-Z]+)((?::[0-9]+)?(?:\/.*)?)$/', $url, $matches ); // get host

0 commit comments

Comments
 (0)