Skip to content

Commit 5e2729a

Browse files
authored
set timeout request on curl
1 parent b6d72e7 commit 5e2729a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

KBBIModel.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private function _fetchHtml($word)
2020
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
2121
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification
2222
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification
23+
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
2324

2425
$response = curl_exec($ch);
2526

@@ -42,6 +43,7 @@ private function _request__KBBI_API_Zhirrr($word)
4243
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
4344
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification
4445
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification
46+
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
4547

4648
$response = curl_exec($ch);
4749

@@ -309,11 +311,16 @@ private function _KBBI_byZhirrr($word): array
309311

310312
public function searchWord($word)
311313
{
312-
// OFFICIAL
313-
$_KBBI_official = $this->_KBBI_official($word);
314-
if(count($_KBBI_official))
315-
{
316-
return $_KBBI_official;
314+
try {
315+
// OFFICIAL
316+
$_KBBI_official = $this->_KBBI_official($word);
317+
if(count($_KBBI_official))
318+
{
319+
return $_KBBI_official;
320+
}
321+
} catch (\Exception $e) {
322+
// Log the error message or handle it as needed
323+
error_log("Official API error: " . $e->getMessage());
317324
}
318325

319326
// ZHIRRR

0 commit comments

Comments
 (0)