Introduction of cURL initialization and execution method of PHP
This article will explain in detail how to initialize and execute PHP cURL. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
This is the basis of collection. You'd better familiarize yourself with it.
$ch = curl_init (); # set url and return the result, whether to return the header curl_setopt ($ch, CURLOPT_URL, 'http://www.baidu.com/');curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($this- > ch, CURLOPT_HEADER, 1); # cookie file settings curl_setopt ($this- > ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt ($this- > ch, CURLOPT_COOKIEFILE, $cookie_file) # extra header curl_setopt ($this- > ch, CURLOPT_HTTPHEADER, array ('User-Agent: Mozilla/5.0')); # set postcurl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $poststring); # connection, execution expiration time curl_setopt ($this- > ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt ($this- > ch, CURLOPT_TIMEOUT, 30); # whether to follow 301 302curl_setopt ($this- > ch, CURLOPT_FOLLOWLOCATION, 1) Curl_setopt ($this- > ch, CURLOPT_MAXREDIRS, 10); # refercurl_setopt ($this- > ch, CURLOPT_REFERER, $refer); # http version and port reuse settings curl_setopt ($this- > ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt ($this- > ch, CURLOPT_FORBID_REUSE, 1); # support httpscurl_setopt ($this- > ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($this- > ch, CURLOPT_SSL_VERIFYHOST, 0) # if you need to perform millisecond timeout, you need to add: curl_setopt ($this- > ch, CURLOPT_NOSIGNAL, 1); # execute $response = curl_exec ($ch); if (curl_errno ($ch)) {curl_error ($ch); exit ();} curl_close ($ch). This is the end of the introduction of cURL initialization and execution methods of PHP. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.