-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add curl library to support multiple proxies #477
Changes from all commits
6852f3a
1041e82
3457105
701ea93
8658d93
01c1691
ff97fa6
2bfc710
536b27d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
function curlgetContents( $url, $params, $post=false){ | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $post ? $url : $url.'?'.http_build_query($params) ); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
#curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/rssbridge-fb-cookies.txt'); | ||
#curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/rssbridge-fb-cookies.txt'); | ||
$files = array_diff(scandir(__DIR__.'/../proxylist/'), array('.', '..')); | ||
$proxies = []; | ||
foreach($files as $file) { | ||
$proxies_str = file_get_contents(__DIR__.'/../proxylist/'.$file); | ||
$proxies = array_merge($proxies, explode("\n", $proxies_str, -1)); | ||
} | ||
$proxy = $proxies[array_rand($proxies)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this work if no proxy is specified (no files in the 'proxylist/' directory)? |
||
curl_setopt($ch, CURLOPT_PROXY, $proxy); | ||
$proxy_d = print_r($proxy, true); | ||
|
||
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); | ||
curl_setopt($ch, CURLOPT_HEADER, 1); | ||
curl_setopt($ch, CURLOPT_VERBOSE, 1); | ||
curl_setopt($ch, CURLINFO_HEADER_OUT, 1); | ||
|
||
if ( $post ) { | ||
curl_setopt($ch, CURLOPT_POST, true); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Content-Type: application/x-www-form-urlencoded', | ||
'User-Agent: '.ini_get('user_agent'), | ||
)); | ||
} else { | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'User-Agent: '.ini_get('user_agent'), | ||
)); | ||
} | ||
|
||
$response = curl_exec($ch); | ||
$info = curl_getinfo($ch); | ||
|
||
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | ||
$header = substr($response, 0, $header_size); | ||
$body = substr($response, $header_size); | ||
|
||
if($errno = curl_errno($ch)) { | ||
$error_message = curl_strerror($errno); | ||
$info = "cURL error ({$errno}):\n {$error_message}"; | ||
} | ||
curl_close($ch); | ||
#file_put_contents(__DIR__.'/../debug/D'.date('H-i-s').'.html', $body); | ||
|
||
rewind($verbose); | ||
$verboseLog = stream_get_contents($verbose); | ||
|
||
return array($body, $info, $header, $proxy_d); | ||
|
||
} | ||
function curlgetSimpleHTMLDOM($url | ||
, $use_include_path = false | ||
, $context = null | ||
, $offset = 0 | ||
, $maxLen = null | ||
, $lowercase = true | ||
, $forceTagsClosed = true | ||
, $target_charset = DEFAULT_TARGET_CHARSET | ||
, $stripRN = true | ||
, $defaultBRText = DEFAULT_BR_TEXT | ||
, $defaultSpanText = DEFAULT_SPAN_TEXT | ||
){ | ||
list($body, $info, $header, $proxy) = curlgetContents($url, $use_include_path, $context, $offset, $maxLen); | ||
return array(str_get_html($body | ||
, $lowercase | ||
, $forceTagsClosed | ||
, $target_charset | ||
, $stripRN | ||
, $defaultBRText | ||
, $defaultSpanText), | ||
$info, $header, $proxy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any need to know |
||
} | ||
?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please have a look at the Travis-CI results. Also checkout the new contributions guidelines regarding coding style. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split this file into a separate PR