In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to solve the problem of error code 7 in php curl". In daily operation, I believe that many people have doubts about how to solve the problem of error code 7 in php curl. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the problem of "how to solve the problem of error code 7 in php curl". Next, please follow the editor to study!
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem of php curl error code 7? Php-how to resolve the CURL error (7): unable to connect to the host?
1. Problem description
Call the third-party interface, call all ok locally, online call failed!
When a third-party interface is called locally through the curLRequest () method, the curl_errno () method returns a result of 0, indicating that the call is successful, while the online curl_errno () method returns a result of 7, and the call fails.
Environment:
Local wamp, online lnmp
In order to eliminate environmental problems, cmd executes the curl function on the server to make a post request to the third-party interface and finds that the call is successful! Call the script to enter:
Curl-I-X POST-H 'Accept:application/json'-H' Content-Type:application/json;charset=utf-8'-H 'Authorization:**='-d' {"voipAccount": "*"} 'URL of the third party interface
Call the key code of the third-party interface:
/ * * @ param $requestUrl | String requested address * @ param bool $https * @ param $headerInfo | array header file information * @ param string $rquestMethod | String request type * @ param $requestData | json sends requested data * @ return mixed * / public function curLRequest ($requestUrl,$requestData,$https=true,$rquestMethod='post') {$headerInfo= ['Accept:application/json' 'Content-Type:application/json Charset=utf-8', 'Authorization:'.self::$auth]; $ch = curl_init (); / / initialize curl_setopt ($ch, CURLOPT_URL, $requestUrl); / / set the URL curl_setopt for access ($ch, CURLOPT_USERAGENT, $_ SERVER [' HTTP_USER_AGENT']); / / simulate the browser curl_setopt used by the user ($ch, CURLOPT_HTTPHEADER, $headerInfo) / / set header information curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); / / only get page content, but not output if ($https) {curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); / / No server authentication curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false) / / No client authentication} if ($rquestMethod = = 'post') {curl_setopt ($ch, CURLOPT_POST, true); / / set the request to POST curl_setopt ($ch, CURLOPT_POSTFIELDS, $requestData); / / set the data requested by POST} $str = curl_exec ($ch) / / perform access and return result if (curl_errno ($ch)) {Log::write ('result =:' .curl_errno ($ch)); return ['statuscode' = >-1,' data' = > 'curl request error with error code' .curl _ errno ($ch)];} Log::write ('result =:' .curl_errno ($ch)) Log::write ('return result:'. $str); curl_close ($ch); / / close curl and release resource return json_decode ($str,true);}
After various checks, the code is correct, my problem is the configuration of the online environment.
two。 Solution.
① opens the config file in the selinux directory
Nano / etc/selinux/config
② finds the line SELINUX=enforcing in the config file
③ change SELINUX=disabled
④ save, exit, restart the server
3. Summary
CURL error 7 failed to connect to permission denied "error is caused when the CURL request is blocked by some firewall or something like that.
You will face this problem when the curl request does not match the standard port.
For example, if you do curl on port 1234, then you will face this problem, because the URL of port 80 will give you easy results.
The most common error has been seen on CentOS and other operating systems with 'selinux''.
You need to disable or change 'selinux'' to allow
At this point, the study of "how to solve the problem of error code 7 in php curl" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.