-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8276863
commit 69b15e0
Showing
20 changed files
with
272 additions
and
1,668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,23 +11,23 @@ | |
/** | ||
* Function sendSimpleRequest | ||
* | ||
* @param string $url URL Target Endpoint | ||
* @param string|array $data Array Data to Request | ||
* @param string $method GET or POST | ||
* @param string $url URL Target Endpoint | ||
* @param string|array|object $data Array Data to Request | ||
* @param string $method GET or POST | ||
* | ||
* @return bool|string|null | ||
* @author : 713uk13m <[email protected]> | ||
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/03/2021 20:38 | ||
*/ | ||
function sendSimpleRequest($url = '', $data = [], $method = 'GET') | ||
function sendSimpleRequest(string $url = '', $data = [], string $method = 'GET') | ||
{ | ||
$target = (!empty($data) && (is_array($data) || is_object($data))) ? $url . '?' . http_build_query($data) : $url; | ||
$method = strtoupper($method); | ||
$curl = curl_init(); | ||
curl_setopt_array($curl, array( | ||
CURLOPT_URL => $target, | ||
CURLOPT_RETURNTRANSFER => TRUE, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 30, | ||
|
@@ -44,9 +44,9 @@ function sendSimpleRequest($url = '', $data = [], $method = 'GET') | |
log_message('error', $message); | ||
} | ||
|
||
return NULL; | ||
} else { | ||
return $response; | ||
return null; | ||
} | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,25 +19,30 @@ | |
* @author 713uk13m <[email protected]> | ||
* @copyright 713uk13m <[email protected]> | ||
*/ | ||
class BackgroundRequest implements ProjectInterface, BackgroundRequestInterface | ||
class BackgroundRequest implements ProjectInterface | ||
{ | ||
const REQUEST_TIMEOUT = 30; | ||
const PORT_SSL = 443; | ||
const PORT_HTTP = 80; | ||
public const REQUEST_TIMEOUT = 30; | ||
public const PORT_SSL = 443; | ||
public const PORT_HTTP = 80; | ||
|
||
use Version; | ||
|
||
/** @var object \nguyenanhung\MyDebug\Benchmark */ | ||
private $benchmark; | ||
|
||
/** @var object \nguyenanhung\MyDebug\Debug Call to class */ | ||
private $logger; | ||
|
||
/** @var bool Set Debug Status */ | ||
public $debugStatus = false; | ||
|
||
/** @var null|string Set level Debug: DEBUG, INFO, ERROR .... */ | ||
public $debugLevel = null; | ||
/** @var null|string Set Logger Path to Save */ | ||
public $debugLoggerPath = null; | ||
/** @var null|string Set Logger Filename to Save */ | ||
public $debugLevel; | ||
|
||
/** @var string Set Logger Path to Save */ | ||
public $debugLoggerPath; | ||
|
||
/** @var string Set Logger Filename to Save */ | ||
public $debugLoggerFilename; | ||
|
||
/** | ||
|
@@ -89,10 +94,10 @@ public function __destruct() | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 10/16/18 17:15 | ||
*/ | ||
public static function backgroundHttpGet($url) | ||
public static function backgroundHttpGet(string $url): bool | ||
{ | ||
$parts = parse_url($url); | ||
if (strtolower($parts['scheme']) == 'https') { | ||
if (strtolower($parts['scheme']) === 'https') { | ||
$fp = fsockopen('ssl://' . $parts['host'], $parts['port'] ?? self::PORT_SSL, $errno, $errStr, self::REQUEST_TIMEOUT); | ||
} else { | ||
$fp = fsockopen($parts['host'], $parts['port'] ?? self::PORT_HTTP, $errno, $errStr, self::REQUEST_TIMEOUT); | ||
|
@@ -103,16 +108,16 @@ public static function backgroundHttpGet($url) | |
} | ||
|
||
return false; | ||
} else { | ||
$out = "GET " . $parts['path'] . "?" . $parts['query'] . " HTTP/1.1\r\n"; | ||
$out .= "Host: " . $parts['host'] . "\r\n"; | ||
$out .= "Content-Type: application/x-www-form-urlencoded\r\n"; | ||
$out .= "Connection: Close\r\n\r\n"; | ||
fwrite($fp, $out); | ||
fclose($fp); | ||
|
||
return true; | ||
} | ||
|
||
$out = "GET " . $parts['path'] . "?" . $parts['query'] . " HTTP/1.1\r\n"; | ||
$out .= "Host: " . $parts['host'] . "\r\n"; | ||
$out .= "Content-Type: application/x-www-form-urlencoded\r\n"; | ||
$out .= "Connection: Close\r\n\r\n"; | ||
fwrite($fp, $out); | ||
fclose($fp); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
|
@@ -127,10 +132,10 @@ public static function backgroundHttpGet($url) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 10/16/18 17:16 | ||
*/ | ||
public static function backgroundHttpPost($url, $paramString = '') | ||
public static function backgroundHttpPost(string $url, string $paramString = ''): bool | ||
{ | ||
$parts = parse_url($url); | ||
if ($parts['scheme'] == 'https') { | ||
if ($parts['scheme'] === 'https') { | ||
$fp = fsockopen('ssl://' . $parts['host'], $parts['port'] ?? self::PORT_SSL, $errno, $errStr, self::REQUEST_TIMEOUT); | ||
} else { | ||
$fp = fsockopen($parts['host'], $parts['port'] ?? self::PORT_HTTP, $errno, $errStr, self::REQUEST_TIMEOUT); | ||
|
@@ -141,19 +146,19 @@ public static function backgroundHttpPost($url, $paramString = '') | |
} | ||
|
||
return false; | ||
} else { | ||
$out = "POST " . $parts['path'] . "?" . $parts['query'] . " HTTP/1.1\r\n"; | ||
$out .= "Host: " . $parts['host'] . "\r\n"; | ||
$out .= "Content-Type: application/x-www-form-urlencoded\r\n"; | ||
$out .= "Content-Length: " . strlen($paramString) . "\r\n"; | ||
$out .= "Connection: Close\r\n\r\n"; | ||
if ($paramString != '') { | ||
$out .= $paramString; | ||
} | ||
fwrite($fp, $out); | ||
fclose($fp); | ||
} | ||
|
||
return true; | ||
$out = "POST " . $parts['path'] . "?" . $parts['query'] . " HTTP/1.1\r\n"; | ||
$out .= "Host: " . $parts['host'] . "\r\n"; | ||
$out .= "Content-Type: application/x-www-form-urlencoded\r\n"; | ||
$out .= "Content-Length: " . strlen($paramString) . "\r\n"; | ||
$out .= "Connection: Close\r\n\r\n"; | ||
if ($paramString !== '') { | ||
$out .= $paramString; | ||
} | ||
fwrite($fp, $out); | ||
fclose($fp); | ||
|
||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.