From 03aaa13acabdd52db9df1435c949f629260db3c5 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Thu, 13 Feb 2020 15:29:25 +0900 Subject: [PATCH] Update webpagetool.php --- helper/webpagetool.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/helper/webpagetool.php b/helper/webpagetool.php index 1358c1a..22fbe10 100644 --- a/helper/webpagetool.php +++ b/helper/webpagetool.php @@ -7,8 +7,7 @@ * @brief WebPageTool helper */ - -/****** START EXAMPLES *****/ +/****** EXAMPLES { *****/ /* * GET: $response = get_web_page($url, "get", $data); */ /* * POST: $response = get_web_page($url, "post", $data); */ /* * GET/CACHE: $response = get_web_page($url, "get.cache", $data); */ @@ -19,7 +18,7 @@ /* * GET/WGET: $response = get_web_page($url, "get.wget"); */ /* * GET/ARIA: $response = get_web_page($url, "get.aria"); */ /* * PRINT: echo $response['content']; */ -/****** END EXAMPLES *****/ +/****** } // END EXAMPLES *****/ if(!is_fn("get_web_fgc")) { function get_web_fgc($url) { @@ -61,6 +60,7 @@ if(!is_fn("get_web_cmd")) { function get_web_cmd($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45, $headers=array()) { $output = ""; + $methods = explode(",", $method); $args = array("curl"); $cmd = ""; @@ -166,6 +166,11 @@ if(!is_fn("get_web_cmd")) { // complete and run command $cmd = trim(implode(" ", $args)); + // do async(background) + if(in_array("async", $methods)) { + $cmd = sprintf("(%s &) & echo $!", $cmd); + } + // run command if(!empty($cmd)) { $output = exec_command($cmd); @@ -496,6 +501,8 @@ if(!is_fn("get_web_page")) { // do request if(in_array("cache", $req_methods)) { $content = get_web_cache($url, $method, $data, $proxy, $ua, $ct_out, $t_out, $headers); + } elseif(in_array("async", $req_methods)) { + $content = get_web_async($url, $req_methods[0], $data, $proxy, $ua, $ct_out, $t_out, $headers); } elseif(in_array("cmd", $req_methods)) { $content = get_web_cmd($url, $req_methods[0], $data, $proxy, $ua, $ct_out, $t_out, $headers); } elseif(in_array("fgc", $req_methods)) { @@ -575,6 +582,17 @@ if(!is_fn("get_web_identifier")) { } } +if(!is_fn("get_web_async")) { + function get_web_async($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45, $headers=array()) { + $pid = 0; + + $_method = sprintf("%s.%s", $method, "async"); + $pid = get_web_cmd($url, $_method, $data, $proxy, $ua, $ct_out, $t_out, $headers); + + return $pid; + } +} + if(!is_fn("get_web_cache")) { function get_web_cache($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45, $headers=array()) { $content = false;