@@ -120,11 +120,17 @@ private function checkNodes()
120120 */
121121 private function tcpCheck ($ ip )
122122 {
123- $ url = 'https://ipcheck.need.sh/api_v2.php?ip= ' . $ ip ;
124- $ ret = $ this ->curlRequest ($ url );
125- $ ret = json_decode ($ ret );
126- if (!$ ret || $ ret ->result != 'success ' ) {
127- Log::warning ("【TCP阻断检测】ipcheck.need.sh的TCP阻断检测接口挂了 " );
123+ try {
124+ $ url = 'https://ipcheck.need.sh/api_v2.php?ip= ' . $ ip ;
125+ $ ret = $ this ->curlRequest ($ url );
126+ $ ret = json_decode ($ ret );
127+ if (!$ ret || $ ret ->result != 'success ' ) {
128+ Log::warning ("【TCP阻断检测】检测 " . $ ip . "时,接口返回异常 " );
129+
130+ return false ;
131+ }
132+ } catch (\Exception $ e ) {
133+ Log::warning ("【TCP阻断检测】检测 " . $ ip . "时,接口请求超时 " );
128134
129135 return false ;
130136 }
@@ -206,15 +212,15 @@ private function curlRequest($url, $data = [])
206212
207213 $ ch = curl_init ();
208214 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
209- curl_setopt ($ ch , CURLOPT_TIMEOUT , 500 );
215+ curl_setopt ($ ch , CURLOPT_TIMEOUT , 10 );
210216 curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , false );
211217 curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , false );
212218 curl_setopt ($ ch , CURLOPT_URL , $ url );
213- curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
214- 'Accept: application/json ' , // 请求报头
215- 'Content-Type: application/json ' , // 实体报头
216- 'Content-Length: ' . strlen ($ data )
217- ]);
219+ // curl_setopt($ch, CURLOPT_HTTPHEADER, [
220+ // 'Accept: application/json', // 请求报头
221+ // 'Content-Type: application/json', // 实体报头
222+ // 'Content-Length: ' . strlen($data)
223+ // ]);
218224
219225 // 如果data有数据,则用POST请求
220226 if ($ data ) {
0 commit comments