In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use the php curl function". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Php curl function usage: 1, use curl_init to create a new cURL resource; 2, set URL and the corresponding options through curl_setopt; 3, grab URL through curl_exec and pass it to the browser; 4, use curl_close to close cURL resources.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
Summary of the usage of curl function of PHP
To use cURL to send an url request, the steps are roughly as follows:
1. Initialization
two。 Set request options
3. Execute a cURL session and get a reply
4. Release the cURL handle and close a cURL session
Basic examples of curl:
Curl function:
Curl_close-closes a cURL session
Curl_copy_handle-copy a cURL handle and all its options
Curl_errno-returns the last error number
Curl_error-returns a string that protects the most recent error in the current session
Curl_escape-Encoding a given string using URL
Curl_exec-execute a cURL session
Curl_file_create-create a CURLFile object
Curl_getinfo-gets information about a cURL connection resource handle
Curl_init-initiates a cURL session
Curl_multi_add_handle-add a separate curl handle to the curl batch session
Curl_multi_close-closes a set of cURL handles
Curl_multi_exec-runs the child connection of the current cURL handle
Curl_multi_getcontent-if CURLOPT_RETURNTRANSFER is set, the text stream of the obtained output is returned
Curl_multi_info_read-gets the transmission information of the currently parsed cURL
Curl_multi_init-returns a new cURL batch handle
Curl_multi_remove_handle-removes a handle resource from a curl batch handle resource
Curl_multi_select-waits for active connections in all cURL batches
Curl_multi_setopt-set an option for cURL parallel processing
Curl_multi_strerror-Return string describing error code
Curl_pause-Pause and unpause a connection
Curl_reset-resets all options for a libcurl session handle
Curl_setopt_array-bulk set options for cURL transport session
Curl_setopt-set a cURL transport option
Curl_share_close-Close a cURL share handle
Curl_share_init-Initialize a cURL share handle
Curl_share_setopt-Set an option for a cURL share handle.
Curl_strerror-Return string describing the given error code
Curl_unescape-Decodes a given URL-encoded string
Curl_version-get cURL version information
Some parameter references
The values of the following options are used as long shaping (specified in the option parameter):
CURLOPT_INFILESIZE: when you upload a file to a remote site, this option tells PHP the size of the file you uploaded.
CURLOPT_VERBOSE: if you want CURL to report everything unexpected, set this option to a non-zero value.
CURLOPT_HEADER: if you want to include a header in the output, set this option to a non-zero value.
CURLOPT_NOPROGRESS: if you can't PHP to display a process bar for CURL transfer, set this option to a non-zero value.
Note: PHP automatically sets this option to a non-zero value, and you should change this option only for debugging purposes.
CURLOPT_NOBODY: if you don't want to include the body section in the output, set this option to a non-zero value.
CURLOPT_FAILONERROR: if you want PHP not to display when an error occurs (HTTP code returns greater than or equal to 300), set this option to an one-person non-zero value. The default behavior is to return a normal page and ignore the code.
CURLOPT_UPLOAD: if you want PHP to prepare for upload, set this option to a non-zero value.
CURLOPT_POST: if you want PHP to be a regular HTTP POST, set this option to a non-zero value. This POST is a normal application/x-www-from-urlencoded type and is mostly used by HTML forms.
CURLOPT_FTPLISTONLY: set this option to a non-zero value, and PHP will list the directory names of FTP.
CURLOPT_FTPAPPEND: set this option to a non-zero value and PHP will apply the remote file instead of overwriting it.
CURLOPT_NETRC: set this option to a non-zero value, and PHP will look up the user name and password of the remote site you want to connect to in your ~. / netrc file.
CURLOPT_FOLLOWLOCATION: set this option to a header with a non-zero value (such as' Location:'), and the server will send it as part of the HTTP header (note that this is recursive, PHP will send a header shaped like 'Location:').
CURLOPT_PUT: set this option to a non-zero value to upload a file with HTTP. To upload this file, you must set the CURLOPT_INFILE and CURLOPT_INFILESIZE options.
CURLOPT_MUTE: set this option to a non-zero value and PHP will be completely silent on the CURL function.
CURLOPT_TIMEOUT: sets a number of long shapers, as the maximum duration of seconds.
CURLOPT_LOW_SPEED_LIMIT: sets a long shaping number that controls how many bytes are transferred.
CURLOPT_LOW_SPEED_TIME: sets a long shaping number that controls how many seconds to transfer the number of bytes specified by CURLOPT_LOW_SPEED_LIMIT.
CURLOPT_RESUME_FROM: pass a long shaping parameter that contains the byte offset address (the start form you want to transfer to).
CURLOPT_SSLVERSION: pass a long parameter that contains the SSL version. The default PHP will be determined by its own efforts, and you have to set it manually for more security.
CURLOPT_TIMECONDITION: pass a long argument that specifies what to do with the CURLOPT_TIMEVALUE parameter. You can set this parameter to TIMECOND_IFMODSINCE or TIMECOND_ISUNMODSINCE. This is for HTTP only.
CURLOPT_TIMEVALUE: pass a number of seconds from 1970-1-1 to the present. This time will be used by the CURLOPT_TIMEVALUE option as the specified value, or by the default TIMECOND_IFMODSINCE.
The values of the following options will be used as strings:
CURLOPT_URL: this is the URL address you want to retrieve with PHP. You can also set this option when initializing with the curl_init () function.
CURLOPT_USERPWD: pass a string in the form of [username]: [password], and use PHP to connect.
CURLOPT_PROXYUSERPWD: pass a string in the form of [username]: [password] to connect to the HTTP proxy.
CURLOPT_RANGE: pass a range that you want to specify. It should be in 'XmurY' format, X or Y is excluded. HTTP transmissions also support several intervals, separated by commas.
CURLOPT_POSTFIELDS: a string that passes all the data as a HTTP "POST" operation.
CURLOPT_REFERER: a string containing a 'referer' header' in the HTTP request.
CURLOPT_USERAGENT: a string containing a 'user-agent' header' in the HTTP request.
CURLOPT_FTPPORT: pass an IP address that is used by the ftp 'POST' instruction. This POST instruction tells the remote server to connect to the IP address we specified. This string can be an IP address, a hostname, a network interface name (under UNIX), or'-'(using the system default IP address).
CURLOPT_COOKIE: pass a header connection that contains HTTP cookie.
CURLOPT_SSLCERT: pass a string containing the certificate in PEM format.
CURLOPT_SSLCERTPASSWD: pass a password that contains the necessary password to use the CURLOPT_SSLCERT certificate.
CURLOPT_COOKIEFILE: a string that passes the name of a file that contains cookie data. The cookie file can be in Netscape format or a HTTP-style header stored in the file.
CURLOPT_CUSTOMREQUEST: when making a HTTP request, passing a character is used by GET or HEAD. For DELETE or other operations is beneficial, more Pass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing or another, more obscure, HTTP request.
Note: do not do this before confirming that your server supports commands.
The following options require a file description (obtained by using the fopen () function):
CURLOPT_FILE: this file will be the output file you placed and transferred. The default is STDOUT.
CURLOPT_INFILE: this file is the input file you sent over.
CURLOPT_WRITEHEADER: this file contains the header of your output.
CURLOPT_STDERR: this file is written with errors instead of stderr.
That's all for "how to use the php curl function". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.