Home Backend Development PHP Tutorial PHP CURL Function Library Page 1/2_PHP Tutorial

PHP CURL Function Library Page 1/2_PHP Tutorial

Jul 21, 2016 pm 03:48 PM
curl php session closure function Library copy connect

curl_close — Close a curl session
curl_copy_handle — Copy all contents and parameters of a curl connection resource
curl_errno — Return a numeric number containing error information of the current session
curl_error — Return a character containing error information of the current session String
curl_exec — Execute a curl session
curl_getinfo — Get information about a curl connection resource handle
curl_init — Initialize a curl session
curl_multi_add_handle — Add a separate curl handle resource to a curl batch session
curl_multi_close — Close a batch handle resource
curl_multi_exec — Parse a curl batch handle
curl_multi_getcontent — Return the text stream of the obtained output
curl_multi_info_read — Get the relevant transmission information of the currently parsed curl
curl_multi_init — Initialize a curl batch handle resource
curl_multi_remove_handle — Remove a handle resource in the curl batch handle resource
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — Set session parameters for a curl in the form of an array
curl_setopt — Set session parameters for a curl
curl_version — Get curl-related version information

The role of the curl_init() function is to initialize a Curl session, the only parameter of the curl_init() function is optional and represents a URL address.
The curl_exec() function is used to execute a curl session. The only parameter is the handle returned by the curl_init() function.
The curl_close() function is used to close a curl session. The only parameter is the handle returned by the curl_init() function.

$ch = curl_init("http://www.baidu.com/");
curl_exec($ch);
curl_close($ch);
?>
The purpose of the curl_version() function is to obtain curl-related version information. The curl_version() function has a parameter, and it is unclear what it does.

print_r(curl_version())
?>
The function of curl_getinfo() function is to obtain the information of a curl connection resource handle. The curl_getinfo() function has two parameters. The first parameter is the resource handle of curl. The second parameter is the following constants:

$ch = curl_init("http://www.baidu.com/");
print_r(curl_getinfo($ch ));
?>
Optional constants include:

CURLINFO_EFFECTIVE_URL
The last valid url address

CURLINFO_HTTP_CODE
The last received HTTP Code

CURLINFO_FILETIME
The time to obtain the document remotely, if it cannot be obtained, the return value is "-1"

CURLINFO_TOTAL_TIME
The time consumed by the last transmission

CURLINFO_NAMELOOKUP_TIME
Time spent on name resolution

CURLINFO_CONNECT_TIME
Time spent establishing connection

CURLINFO_PRETRANSFER_TIME
Time spent from establishing connection to preparing for transfer

CURLINFO_STARTTRANSFER_TIME
Time elapsed from establishment of connection to start of transfer

CURLINFO_REDIRECT_TIME
Time elapsed for redirection before transaction transfer begins

CURLINFO_SIZE_UPLOAD
Upload Total value of data volume

CURLINFO_SIZE_DOWNLOAD
Total value of downloaded data volume

CURLINFO_SPEED_DOWNLOAD
Average download speed

CURLINFO_SPEED_UPLOAD
Average upload speed

CURLINFO_HEADER_SIZE
The size of the header part

CURLINFO_HEADER_OUT
The string to send the request

CURLINFO_REQUEST_SIZE
The size of the request in question in the HTTP request

CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER

CURLINFO_CONTENT_LENGTH_DOWNLOAD
Download content length read from Content-Length: field

CURLINFO_CONTENT_LENG TH_UPLOAD
Upload content Description of size

CURLINFO_CONTENT_TYPE
The "Content-type" value of the downloaded content, NULL means that the server did not send a valid "Content-Type: header"

The function of curl_setopt() function is Set session parameters for a curl. The curl_setopt_array() function is used to set session parameters for a curl in the form of an array.

$ch = curl_init();
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $ fp);
$options = array(
CURLOPT_URL => 'http://www.baidu.com/',
CURLOPT_HEADER => false
);
curl_setopt_array($ ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
The parameters that can be set are:

CURLOPT_AUTOREFERER
Automatically set the referer information in the header

CURLOPT_BINARYTRANSFER
When CURLOPT_RETURNTRANSFER is enabled, the data will be retrieved and returned

CURLOPT_COOKIESESSION
When enabled, curl will only pass one session cookie, ignore other cookies, curl will return all cookies to the server by default. Session cookies refer to cookies that are used to determine whether the server-side session is valid.

CURLOPT_CRLF
When enabled, convert Unix line feed characters into carriage return and line feed characters.

CURLOPT_DNS_USE_GLOBAL_CACHE
When enabled, a global DNS cache is enabled. This item is thread-safe and defaults to true.

CURLOPT_FAILONERROR
Displays the HTTP status code. The default behavior is to ignore HTTP information with a number less than or equal to 400.

CURLOPT_FILETIME
When enabled, it will try to modify the information in the remote document. The result information will be returned through the CURLINFO_FILETIME option of the curl_getinfo() function.

CURLOPT_FOLLOWLOCATION
When enabled, the "Location:" returned by the server will be placed in the header and returned to the server recursively. Use CURLOPT_MAXREDIRS to limit the number of recursive returns.

CURLOPT_FORBID_REUSE
Forcibly disconnect after completing the interaction and cannot be reused.

CURLOPT_FRESH_CONNECT
Force a new connection to replace the one in the cache.

CURLOPT_FTP_USE_EPRT
TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.
Added in PHP 5.0.0.

CURLOPT_FTP_USE_EPSV
TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.

CURLOPT_FTPAPPEND
TRUE to append to the remote file instead of overwriting it .

CURLOPT_FTPASCII
An alias of CURLOPT_TRANSFERTEXT. Use that instead.

CURLOPT_FTPLISTONLY
TRUE to only list the names of an FTP directory. >When enabled, the header file information will be output as a data stream.

CURLOPT_HTTPGET
When enabled, the HTTP method will be set to GET. Because GET is the default, it is only used when it is modified.

CURLOPT_HTTPPROXYTUNNEL
When enabled, it will be transmitted through HTTP proxy.

CURLOPT_MUTE
Restore all modified parameters in the curl function to their default values.

CURLOPT_NETRC
After the connection is established, access the ~/.netrc file to obtain the username and password information to connect to the remote site.

CURLOPT_NOBODY
When enabled, the body part of the HTML will not be output.

CURLOPT_NOPROGRESS
When enabled, turn off the progress bar of curl transmission. The default setting of this item is true

CURLOPT_NOSIGNAL
When enabled, ignore all signals passed by curl to PHP. This item is turned on by default during SAPI multi-thread transmission.

CURLOPT_POST
When enabled, a regular POST request will be sent of type: application/x-www-form-urlencoded, just like a form submission.

CURLOPT_PUT
When enabled, HTTP is allowed to send files. CURLOPT_INFILE and CURLOPT_INFILESIZE must be set at the same time.

CURLOPT_RETURNTRANSFER
The information obtained by curl_exec() is returned in the form of a file stream instead of directly output.

CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2). TRUE by default as of cURL 7.10. Default bundle installed as of cURL 7.10.

CURLOPT_TRANSFERTEXT
TRUE to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode.

CURLOPT_UNRESTRICTED_AUTH
Continuously append users to multiple locations in the header generated using CURLOPT_FOLLOWLOCATION name and password information, even if the domain name has changed.

CURLOPT_UPLOAD
Allow file transfer when enabled

CURLOPT_VERBOSE
When enabled, all information will be reported and stored in STDERR or the specified CURLOPT_STDERR

CURLOPT_BUFFERSIZE
The size of the cache is read each time the data is obtained, and this value will be filled every time.

CURLOPT_CLOSEPOLICY
It is either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST. There are three others, but curl does not support them yet. .

CURLOPT_CONNECTTIMEOUT
The time to wait before initiating a connection. If set to 0, there will be no waiting.



http://www.bkjia.com/PHPjc/319643.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319643.htmlTechArticlecurl_close — Close a curl session curl_copy_handle — Copy all contents and parameters of a curl connection resource curl_errno — Return a file containing the current The numeric number of the session error message...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles