From e4725b4983c6641f70e4e09727a5ffdeb44f6203 Mon Sep 17 00:00:00 2001 From: Javad Ezaz Date: Sat, 15 Apr 2023 19:33:52 +0330 Subject: [PATCH 1/3] feat: add timeout for curl --- src/KavenegarApi.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/KavenegarApi.php b/src/KavenegarApi.php index ff0e946..200382e 100644 --- a/src/KavenegarApi.php +++ b/src/KavenegarApi.php @@ -12,7 +12,10 @@ class KavenegarApi { const APIPATH = "%s://api.kavenegar.com/v1/%s/%s/%s.json/"; const VERSION = "1.2.2"; - public function __construct($apiKey,$insecure=false) + + private $timeout; + + public function __construct($apiKey,$insecure=false,$timeout=null) { if (!extension_loaded('curl')) { die('cURL library is not loaded'); @@ -22,9 +25,14 @@ public function __construct($apiKey,$insecure=false) die('apiKey is empty'); exit; } + if (!is_numeric($timeout)) { + die('timeout must be number'); + exit; + } $this->apiKey = trim($apiKey); $this->insecure = $insecure; - } + $this->timeout = $timeout; + } protected function get_path($method, $base = 'sms') { @@ -50,7 +58,11 @@ protected function execute($url, $data = null) curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($handle, CURLOPT_POST, true); curl_setopt($handle, CURLOPT_POSTFIELDS, $fields_string); - + + if (! empty($this->timeout)) { + curl_setopt($handle, CURLOPT_TIMEOUT, $this->timeout); + } + $response = curl_exec($handle); $code = curl_getinfo($handle, CURLINFO_HTTP_CODE); $content_type = curl_getinfo($handle, CURLINFO_CONTENT_TYPE); @@ -290,5 +302,21 @@ public function CallMakeTTS($receptor, $message, $date = null, $localid = null) ); return $this->execute($path, $params); } + + /** + * @return float|int|string + */ + public function getTimeout() + { + return $this->timeout; + } + + /** + * @param float|int|string $timeout + */ + public function setTimeout($timeout) + { + $this->timeout = $timeout; + } } ?> \ No newline at end of file From 95f76690ae4d5d62fd0ca09f1e390c28447ad3d0 Mon Sep 17 00:00:00 2001 From: Javad Ezaz Date: Sat, 15 Apr 2023 19:35:54 +0330 Subject: [PATCH 2/3] feat: change package name and homepage --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1ba9d47..74a7d14 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "kavenegar/php", + "name": "sjavadez/php", "type": "library", "description": "A PHP wrapper for Kavenegar's API", "keywords": ["kavenegar", "sms", "api"], - "homepage": "http://github.com/Kavenegar/kavenegar-php", + "homepage": "https://github.com/sjavadez/kavenegar-php", "license": "MIT", "authors": [ { From 5fdc5100ab142aaf73d50703d97a9ff3173edfa9 Mon Sep 17 00:00:00 2001 From: Javad Ezaz Date: Sat, 15 Apr 2023 19:40:51 +0330 Subject: [PATCH 3/3] feat: change package name and homepage --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 74a7d14..8c76d46 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sjavadez/php", + "name": "sjavadez/kavenegar-php", "type": "library", "description": "A PHP wrapper for Kavenegar's API", "keywords": ["kavenegar", "sms", "api"],