How to use php cURL function

藏色散人
Release: 2023-02-22 20:34:02
Original
2829 people have browsed it

In order to use PHP's cURL functions, you need to install the » libcurl package. PHP requires libcurl 7.0.2-beta or higher. To use cURL with PHP 4.2.3, you need to install libcurl version 7.9.0 or higher.

How to use php cURL function

#php How to use cURL function?

Overview

The libcurl library created by Daniel Stenberg, supported by PHP, allows you to connect and communicate with a variety of servers using various types of protocols.

libcurl currently supports http, https, ftp, gopher, telnet, dict, file and ldap protocols. libcurl also supports HTTPS authentication, HTTP POST, HTTP PUT, FTP upload (this can also be accomplished through PHP's FTP extension), HTTP form-based upload, proxy, cookies, and username and password authentication.

How to use cURL to implement Get and Post requests in PHP

These functions were introduced in PHP 4.0.2.

Requirements

In order to use PHP's cURL function, you need to install the » libcurl package.

PHP requires libcurl 7.0.2-beta or higher. To use cURL with PHP 4.2.3, you need to install libcurl version 7.9.0 or higher. Starting with PHP 4.3.0 you need to install libcurl version 7.9.0 or higher. Starting with PHP 5.0.0 you need to install version 7.10.5 or higher of libcurl.

Installation

To use PHP's cURL support you must add the --with-curl[=DIR] option when compiling PHP. DIR contains lib and include directory path. There must be a folder named curl that contains easy.h and curl.h in the include directory. There should be a file named libcurl.a in the lib folder. For PHP 4.3.0 you can configure --with-curlwrappers to make cURL use URL streams.

Note:

Note for Win32 users To use this module in a Windows environment, libeay32.dll and ssleay32.dll must be placed in the directory included in the PATH environment variable. Do not use libcurl.dll from the cURL website.

Resource type

This extension defines 2 resources: cURL handle and cURL batch handle.

PHP cURL functions

The following contains a list of PHP cURL functions:

Function

curl_close()关闭一个cURL会话。
curl_copy_handle()复制一个cURL句柄和它的所有选项。
curl_errno()返回最后一次的错误号。
curl_error()返回一个保护当前会话最近一次错误的字符串。
curl_escape()返回转义字符串,对给定的字符串进行URL编码。
curl_exec()执行一个cURL会话。
curl_file_create()创建一个 CURLFile 对象。
curl_getinfo()获取一个cURL连接资源句柄的信息。
curl_init()初始化一个cURL会话。
curl_multi_add_handle()向curl批处理会话中添加单独的curl句柄。
curl_multi_close()关闭一组cURL句柄。
curl_multi_exec()运行当前 cURL 句柄的子连接。
curl_multi_getcontent()如果设置了CURLOPT_RETURNTRANSFER,则返回获取的输出的文本流。
curl_multi_info_read()获取当前解析的cURL的相关传输信息。
curl_multi_init()返回一个新cURL批处理句柄。
curl_multi_remove_handle()移除curl批处理句柄资源中的某个句柄资源。
curl_multi_select()等待所有cURL批处理中的活动连接。
curl_multi_setopt()设置一个批处理cURL传输选项。
curl_multi_strerror()返回描述错误码的字符串文本。
curl_pause()暂停及恢复连接。
curl_reset()重置libcurl的会话句柄的所有选项。
curl_setopt_array()为cURL传输会话批量设置选项。
curl_setopt()设置一个cURL传输选项。
curl_share_close()关闭cURL共享句柄。
curl_share_init()初始化cURL共享句柄。
curl_share_setopt()设置一个共享句柄的cURL传输选项。
curl_strerror()返回错误代码的字符串描述。
curl_unescape()解码URL编码后的字符串。
curl_version()获取cURL版本信息。
Copy after login

The above is the detailed content of How to use php cURL function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template