Update webpagetool.php

This commit is contained in:
Namhyeon Go 2018-11-26 19:37:30 +09:00 committed by GitHub
parent e69a62e345
commit f065362abb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,35 +197,14 @@ if(!function_exists("get_web_wget")) {
}
}
if(!function_exists("get_web_page")) {
function get_web_page($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45) {
$status = "-1";
$resno = "-1";
$errno = "-1";
$req_method = $method;
if(!function_exists("get_web_curl")) {
function get_web_curl($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45, $headers=array()) {
$content = false;
$method = strtolower($method);
$res_methods = explode(".", $method);
if(in_array("cache", $res_methods)) {
$content = get_web_cache($url, $method, $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("cmd", $res_methods)) {
$content = get_web_cmd($url, $res_methods[0], $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("fgc", $res_methods)) {
$content = get_web_fgc($url);
} elseif(in_array("sock", $res_methods)) {
$content = get_web_sock($url, $res_methods[0], $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("wget", $res_methods)) {
$content = get_web_wget($url, $res_methods[0], $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("jsondata", $res_methods)) {
$content = get_web_cmd($url, "jsondata", $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("bearer", $res_methods)) {
$content = get_web_bearer($url, $res_methods[0], $data, $proxy, $ua, $ct_out, $t_out);
} else {
if(!in_array("curl", get_loaded_extensions())) {
$error_msg = "cURL extension needs to be installed.";
set_error($error_msg);
return $error_msg;
show_errors();
}
$options = array(
@ -263,22 +242,65 @@ if(!function_exists("get_web_page")) {
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$result = array(
"content" => $content,
"status" => curl_getinfo($ch, CURLINFO_HTTP_CODE),
"resno" => curl_getinfo($ch, CURLINFO_RESPONSE_CODE),
"errno" => curl_errno($ch)
);
if(!is_string($content)) {
curl_close($ch);
return $result;
}
}
if(!function_exists("get_web_page")) {
function get_web_page($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45) {
$status = false;
$resno = false;
$errno = false;
$req_method = $method;
$content = false;
$headers = array();
// redefine data
if(array_key_is_array("headers", $data)) {
$headers = $data['headers'];
$data = $data['data'];
}
// set method
$method = strtolower($method);
$res_methods = explode(".", $method);
if(in_array("cache", $res_methods)) {
$content = get_web_cache($url, $method, $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("cmd", $res_methods)) {
$content = get_web_cmd($url, $res_methods[0], $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("fgc", $res_methods)) {
$content = get_web_fgc($url);
} elseif(in_array("sock", $res_methods)) {
$content = get_web_sock($url, $res_methods[0], $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("wget", $res_methods)) {
$content = get_web_wget($url, $res_methods[0], $data, $proxy, $ua, $ct_out, $t_out);
} elseif(in_array("jsondata", $res_methods)) {
$content = get_web_cmd($url, "jsondata", $data, $proxy, $ua, $ct_out, $t_out, $headers);
} else {
$curl_result = get_web_curl($url, $method, $data, $proxy, $ua, $ct_out, $t_out, $headers);
$content = $curl_result['content'];
if($content !== false) {
$status = $curl_result['status'];
$resno = $curl_result['resno'];
$errno = $curl_result['errno'];
} else {
$res = get_web_page($url, $method . ".cmd", $data, $proxy, $ua, $ct_out, $t_out);
$content = $res['content'];
$req_method = $res['method'];
} else {
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$resno = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$errno = curl_errno($ch);
}
curl_close($ch);
}
$content_size = strlen($content);
$gz_content = gzdeflate($content);
$gz_content_size = strlen($gz_content);
$gz_ratio = ($content_size > 0) ? (floatval($gz_content_size) / floatval($content_size)) : 1.0;