Home  >  Article  >  Backend Development  >  Introduction to the difference between curl and libcurl_PHP tutorial

Introduction to the difference between curl and libcurl_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:47:41951browse

A brief introduction to the difference between curl and libcurl

This article mainly introduces an introduction to the difference between curl and libcurl. This article explains an introduction to curl, an introduction to libcurl, a comparison between curl and libcurl, and "curl "The different meanings of ", the use of curl and libcurl in PHP, etc. There are so many curls that I can't understand. Only after reading this article did I know that what we have been using is actually libcurl. Friends who need it can refer to it

Introduction to curl

Curl is an open source file transfer tool that uses URL syntax to work in command line mode.

It supports many protocols: DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP.

curl also supports SSL certificates, HTTP POST, HTTP PUT, FTP upload, form-based HTTP upload, proxies, cookies, username/password authentication (Basic, Digest, NTLM, etc.), download file breakpoint continuation Transfer, file transfer resume, http proxy tunneling and other features.

Curl was developed by the Swedish curl organization. The official website of curl is http://curl.haxx.se/. Its source code and related instructions can be obtained from the official website.

Introduction to libcurl

Libcurl is a free and open source client-side URL transmission library that supports DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP , SMTP, SMTPS, Telnet and TFTP and other protocols.

Like curl, libcurl also supports SSL certificates, HTTP POST, HTTP PUT, FTP upload, form-based HTTP upload, proxies, cookies, username/password authentication (Basic, Digest, NTLM, etc.), download File transfer resume, file transfer resume, http proxy tunneling, etc.

Libcurl is highly portable and can work on different platforms, supporting Windows, Unix, Linux, etc.

Libcurl is free, thread-safe, IPV6-compatible, and has many other very rich features. libcurl has been adopted by many well-known large enterprises and applications.

You can get the source code and related documents of libcurl here.

Comparison between curl and libcurl

Similarities

Both curl and libcurl can use a variety of protocols to transfer files, including HTTP, HTTPS, FTP, FTPS, GOPHER, LDAP, DICT, TELNET and FILE, etc.

Differences

Curl is a command line tool that can be run through shell or script. The underlying library used by curl is libcurl.

Libcurl is a library that is usually bundled with other programs. For example, the command line tool curl encapsulates the libcurl library. So we can also use libcurl in your own program or project to get powerful features like CURL. The PHP extension to be introduced next is an encapsulation of curl.

Several nouns

Different meanings of “curl”

 1.curl refers to the curl command line tool, which can run curl from the command line or script or batch file. Curl was created in 1998 and provides over 100 options to control it.

 2.cURL is the name of a software project. This software project includes curl and libcurl mentioned above, and both are open source.

 3.CURL is usually used as the name of the libcurl extension in PHP. This extension ensures that PHP programmers can access the functionality provided by the libcurl library in their programs.

curl—command line tool

 1. Command line tool, which can be run from shell or script.

2. Provides more than 130 different "flags"

3. Usually used to simulate browser behavior

4. Cross-platform

libcurl—library

 1. Used as a development library for other programs

2. Can be combined with many languages, such as PHP, C

 3. Cross-platform

4. Provides a variety of different APIs for using it

Using curl and libcurl in PHP

Using curl in PHP

Using curl in PHP is very simple, just call several related functions in PHP that execute system commands.

Code example:

The code is as follows:

$baidu=shell_exec("/usr/bin/curl -L http://www.baidu.com");

var_dump($baidu);

Using libcurl in PHP

Use libcurl in PHP, which is what we usually call "curl" in PHP. This part of the content will be given in a future article. Here is just a sample code:

The code is as follows:

// FTP this script to a server

$fp = fopen(__FILE__, "r");

$url = "ftp://username:password@mydomain.com:21/path/to/newfile.php";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_UPLOAD, 1);

curl_setopt($ch, CURLOPT_INFILE, $fp);

curl_setopt($ch, CURLOPT_FTPASCII, 1);

curl_setopt($ch, CURLOPT_INFILESIZE, filesize(__FILE__));

$result = curl_exec($ch);

curl_close($ch);

Should I use curl or libcurl?

Whether to use curl or libcurl depends on the specific situation. For example, we should use curl when there is a scheduled script that sends an email when a file on the remote server changes or the current PHP environment does not support libcurl. Otherwise, we can use libcurl.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1025329.htmlTechArticleIntroduction to the difference between curl and libcurl This article mainly introduces an introduction to the difference between curl and libcurl. This article explains an introduction to curl. , Introduction to libcurl, comparison between curl and libcurl, different meanings of curl, PHP...
Statement:
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