Skip to content

Commit 7e3e9c9

Browse files
authored
Update KBBIModel.php
1 parent 5e2729a commit 7e3e9c9

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

KBBIModel.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ 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);
23+
curl_setopt($ch, CURLOPT_USERAGENT, 'Localhost');
24+
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Forwarded-For: 127.0.0.1']);
25+
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
26+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
27+
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
28+
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
2429

2530
$response = curl_exec($ch);
2631

@@ -43,7 +48,12 @@ private function _request__KBBI_API_Zhirrr($word)
4348
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
4449
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification
4550
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification
46-
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
51+
curl_setopt($ch, CURLOPT_USERAGENT, 'Localhost');
52+
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Forwarded-For: 127.0.0.1']);
53+
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
54+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
55+
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
56+
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
4757

4858
$response = curl_exec($ch);
4959

@@ -319,15 +329,14 @@ public function searchWord($word)
319329
return $_KBBI_official;
320330
}
321331
} catch (\Exception $e) {
332+
// ZHIRRR
333+
$_KBBI_byZhirrr = $this->_KBBI_byZhirrr($word);
334+
if(count($_KBBI_byZhirrr))
335+
{
336+
return $_KBBI_byZhirrr;
337+
}
322338
// Log the error message or handle it as needed
323-
error_log("Official API error: " . $e->getMessage());
324-
}
325-
326-
// ZHIRRR
327-
$_KBBI_byZhirrr = $this->_KBBI_byZhirrr($word);
328-
if(count($_KBBI_byZhirrr))
329-
{
330-
return $_KBBI_byZhirrr;
339+
// error_log("Official API error: " . $e->getMessage());
331340
}
332341

333342
return false;

0 commit comments

Comments
 (0)