Skip to content

Commit

Permalink
set timeout request on curl
Browse files Browse the repository at this point in the history
  • Loading branch information
dyazincahya authored Nov 3, 2024
1 parent b6d72e7 commit 5e2729a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions KBBIModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private function _fetchHtml($word)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

$response = curl_exec($ch);

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

$response = curl_exec($ch);

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

public function searchWord($word)
{
// OFFICIAL
$_KBBI_official = $this->_KBBI_official($word);
if(count($_KBBI_official))
{
return $_KBBI_official;
try {
// OFFICIAL
$_KBBI_official = $this->_KBBI_official($word);
if(count($_KBBI_official))
{
return $_KBBI_official;
}
} catch (\Exception $e) {
// Log the error message or handle it as needed
error_log("Official API error: " . $e->getMessage());
}

// ZHIRRR
Expand Down

0 comments on commit 5e2729a

Please sign in to comment.