Add wrapper around running curl (runCurl)
This commit is contained in:
parent
790e332502
commit
c73d279ff0
27
MD_STD.php
27
MD_STD.php
|
@ -115,4 +115,31 @@ class MD_STD {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for curling contents from the web.
|
||||
*
|
||||
* @param string $url URL to query.
|
||||
* @param integer $timeout Timeout in milliseconds.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function runCurl(string $url, int $timeout = 1200):string {
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $timeout); //timeout in seconds
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT_MS, $timeout); //timeout in seconds
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, 'md-bot/1.0');
|
||||
$result = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
if (is_bool($result)) return "";
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user