Skip to content

Commit 09b672b

Browse files
authored
Merge pull request #41 from nguyenanhung/develop
Fix class Request phần ghi Log
2 parents b261219 + 6d78228 commit 09b672b

File tree

8 files changed

+114
-96
lines changed

8 files changed

+114
-96
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[![Latest Unstable Version](https://poser.pugx.org/nguyenanhung/requests/v/unstable)](https://packagist.org/packages/nguyenanhung/requests)
44
[![composer.lock](https://poser.pugx.org/nguyenanhung/requests/composerlock)](https://packagist.org/packages/nguyenanhung/requests)
55
[![License](https://poser.pugx.org/nguyenanhung/requests/license)](https://packagist.org/packages/nguyenanhung/requests)
6-
76
# My Requests
87

98
Library Interface Requests use cURL, File Get Contents, SOAP Requests
@@ -159,7 +158,7 @@ d($result);
159158

160159
### Contact
161160

162-
If any quetion & request, please contact following infomation
161+
If any question & request, please contact following information
163162

164163
| Name | Email | Skype | Facebook |
165164
| ----------- | -------------------- | ---------------- | ------------- |

composer.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
"require": {
2222
"ext-curl": "*",
2323
"ext-json": "*",
24-
"paragonie/random_compat": "^2.0",
25-
"paragonie/sodium_compat": "^1.13",
24+
"paragonie/random_compat": "^9.99",
25+
"paragonie/sodium_compat": "^1.14",
2626
"ircmaxell/password-compat": "^1.0",
27-
"symfony/http-foundation": "^4.4",
28-
"php-curl-class/php-curl-class": "^8.8",
29-
"react/promise": "^2.8",
30-
"guzzlehttp/guzzle": "^6.5",
31-
"markrogoyski/ipv4-subnet-calculator": "^2.1",
32-
"mlocati/ip-lib": "^1.12",
27+
"symfony/http-foundation": "^5.2",
28+
"php-curl-class/php-curl-class": "^8.9",
29+
"guzzlehttp/guzzle": "^7.2",
30+
"markrogoyski/ipv4-subnet-calculator": "^3.1",
31+
"mlocati/ip-lib": "^1.14",
3332
"nguyenanhung/nusoap": "^0.9.5",
3433
"nguyenanhung/my-debug": "^2.0"
3534
},

src/BackgroundRequest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
/**
1717
* Class BackgroundRequest
1818
*
19-
* @package nguyenanhung\MyRequests
20-
* @author 713uk13m <[email protected]>
21-
* @copyright 713uk13m <[email protected]>
19+
* @package nguyenanhung\MyRequests
20+
* @author 713uk13m <[email protected]>
21+
* @copyright 713uk13m <[email protected]>
2222
*/
2323
class BackgroundRequest implements ProjectInterface, BackgroundRequestInterface
2424
{
25+
const REQUEST_TIMEOUT = 30;
26+
const PORT_SSL = 443;
27+
const PORT_HTTP = 80;
28+
2529
use Version;
2630

2731
/** @var object \nguyenanhung\MyDebug\Benchmark */
@@ -90,9 +94,9 @@ public static function backgroundHttpGet($url)
9094
{
9195
$parts = parse_url($url);
9296
if (strtolower($parts['scheme']) == 'https') {
93-
$fp = fsockopen('ssl://' . $parts['host'], isset($parts['port']) ? $parts['port'] : 443, $errno, $errStr, 30);
97+
$fp = fsockopen('ssl://' . $parts['host'], isset($parts['port']) ? $parts['port'] : self::PORT_SSL, $errno, $errStr, self::REQUEST_TIMEOUT);
9498
} else {
95-
$fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80, $errno, $errStr, 30);
99+
$fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : self::PORT_HTTP, $errno, $errStr, self::REQUEST_TIMEOUT);
96100
}
97101
if (!$fp) {
98102
if (function_exists('log_message')) {
@@ -128,9 +132,9 @@ public static function backgroundHttpPost($url, $paramString = '')
128132
{
129133
$parts = parse_url($url);
130134
if ($parts['scheme'] == 'https') {
131-
$fp = fsockopen('ssl://' . $parts['host'], isset($parts['port']) ? $parts['port'] : 443, $errno, $errStr, 30);
135+
$fp = fsockopen('ssl://' . $parts['host'], isset($parts['port']) ? $parts['port'] : self::PORT_SSL, $errno, $errStr, self::REQUEST_TIMEOUT);
132136
} else {
133-
$fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80, $errno, $errStr, 30);
137+
$fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : self::PORT_HTTP, $errno, $errStr, self::REQUEST_TIMEOUT);
134138
}
135139
if (!$fp) {
136140
if (function_exists('log_message')) {

src/GetContents.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,25 @@ class GetContents implements ProjectInterface, GetContentsInterface
6767
/** @var bool|mixed Should we track cookies? This does not stop the processing of cookies, it just allows for any received cookies to be sent in subsequent requests. Great for scraping. */
6868
private $trackCookies = TRUE;
6969

70-
/** @var bool|boolean Is the request sent in XML and received in XML */
70+
/** @var bool Is the request sent in XML and received in XML */
7171
private $isXML = FALSE;
7272

73-
/** @var bool|boolean Is the request sent in JSON and received in JSON */
73+
/** @var bool Is the request sent in JSON and received in JSON */
7474
private $isJson = FALSE;
7575

76-
/** @var bool|boolean Is the response decode Json to Object */
76+
/** @var bool Is the response decode Json to Object */
7777
private $isDecodeJson = FALSE;
7878

79-
/** @var bool|boolean Should JSON be sent in JSON_PRETTY_PRINT? Only really useful for debugging. */
79+
/** @var bool Should JSON be sent in JSON_PRETTY_PRINT? Only really useful for debugging. */
8080
private $isJsonPretty = FALSE;
8181

8282
/** @var bool|mixed Should SSL peers be verified. You should have a good reason for turning this off. */
8383
private $verifyPeer = TRUE;
8484

85-
/** @var int|integer How long to wait for a server to respond to a request. */
85+
/** @var int How long to wait for a server to respond to a request. */
8686
private $timeout = 60;
8787

88-
/** @var bool|boolean Internal flag to track if the request is in SSL or not. */
88+
/** @var bool Internal flag to track if the request is in SSL or not. */
8989
private $isSSL = FALSE;
9090

9191
/**

src/Input.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function inputStream($index = NULL, $xss_clean = NULL)
117117
if (!is_array($this->inputStream)) {
118118
// $this->raw_input_stream will trigger __get().
119119
parse_str($this->rawInputStream, $this->inputStream);
120-
is_array($this->inputStream) OR $this->inputStream = array();
120+
is_array($this->inputStream) or $this->inputStream = array();
121121
}
122122

123123
return $this->fetchFromArray($this->inputStream, $index, $xss_clean);
@@ -392,7 +392,7 @@ public function isAjax()
392392
*/
393393
public function isCLI()
394394
{
395-
return (PHP_SAPI === 'cli' OR defined('STDIN'));
395+
return (PHP_SAPI === 'cli' or defined('STDIN'));
396396
}
397397

398398
// -------------------------------------------------------------------- //
@@ -412,9 +412,9 @@ public function isCLI()
412412
*/
413413
public function fetchFromArray(&$array, $index = NULL, $xss_clean = NULL)
414414
{
415-
is_bool($xss_clean) OR $xss_clean = $this->enableXss;
415+
is_bool($xss_clean) or $xss_clean = $this->enableXss;
416416
// If $index is NULL, it means that the whole $array is requested
417-
isset($index) OR $index = array_keys($array);
417+
isset($index) or $index = array_keys($array);
418418
// allow fetching multiple keys at once
419419
if (is_array($index)) {
420420
$output = array();

src/Interfaces/ProjectInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
interface ProjectInterface
2020
{
21-
const VERSION = '2.0.0';
22-
const LAST_MODIFIED = '2020-10-02';
21+
const VERSION = '2.0.1';
22+
const LAST_MODIFIED = '2021-01-21';
2323
const MIN_PHP_VERSION = '5.3';
2424
const GET = 'GET';
2525
const HEAD = 'HEAD';

src/Ip.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public function getIpByHaProxy($convertToInteger = FALSE)
9595
$ip = trim($ip);
9696
if ($this->ipValidate($ip)) {
9797
if ($convertToInteger === TRUE) {
98-
$result = ip2long($ip);
99-
100-
return $result;
98+
return ip2long($ip);
10199
}
102100

103101
return $ip;
@@ -137,9 +135,7 @@ public function getRawIpAddress($convertToInteger = FALSE)
137135
$ip = trim($ip);
138136
if ($this->ipValidate($ip)) {
139137
if ($convertToInteger === TRUE) {
140-
$result = ip2long($ip);
141-
142-
return $result;
138+
return ip2long($ip);
143139
}
144140

145141
return $ip;
@@ -172,9 +168,8 @@ public function ipInRange($ip_address = '', $network_range = '')
172168
try {
173169
$address = Factory::addressFromString($ip_address);
174170
$range = Factory::rangeFromString($network_range);
175-
$result = $address->matches($range);
176171

177-
return $result;
172+
return $address->matches($range);
178173
}
179174
catch (Exception $e) {
180175
$result = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
@@ -305,7 +300,7 @@ public function ip2longV6($ip)
305300
* @return string|null
306301
* @author : 713uk13m <[email protected]>
307302
* @copyright: 713uk13m <[email protected]>
308-
* @time : 08/08/2020 47:51
303+
* @time : 01/21/2021 58:35
309304
*/
310305
public function ipInfo($ip = '')
311306
{
@@ -315,18 +310,17 @@ public function ipInfo($ip = '')
315310
try {
316311
$curl = new Curl();
317312
$curl->get('http://ip-api.com/json/' . $ip);
318-
$response = $curl->error ? "cURL Error: " . $curl->errorMessage : $curl->response;
319313

320-
return $response;
314+
return $curl->error ? "cURL Error: " . $curl->errorMessage : $curl->response;
321315
}
322316
catch (Exception $e) {
323-
$message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
324317
if (function_exists('log_message')) {
325318
log_message('error', 'Error Message: ' . $e->getMessage());
326319
log_message('error', 'Error Trace As String: ' . $e->getTraceAsString());
327320
}
328321

329-
return $message;
322+
return 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
323+
330324
}
331325
}
332326
}

0 commit comments

Comments
 (0)