ASPN ActiveState Programmer Network
  ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH
advanced | search help

Reference
PHP Manual
Function Reference
Apache-specific Functions
Array Functions
Aspell functions [deprecated]
BCMath Arbitrary Precision Mathematics Functions
Bzip2 Compression Functions
Calendar functions
CCVS API Functions
COM support functions for Windows
Class/Object Functions
ClibPDF functions
CURL, Client URL Library Functions
Cybercash payment functions
Crédit Mutuel CyberMUT functions
Character type functions
Database (dbm-style) abstraction layer functions
Date and Time functions
dBase functions
DBM Functions
dbx functions
DB++ Functions
Directory functions
DOM XML functions
Error Handling and Logging Functions
FrontBase Functions
filePro functions
Filesystem functions
Forms Data Format functions
FTP functions
Function Handling functions
Gettext
GMP functions
HTTP functions
Hyperwave functions
ICAP Functions
iconv functions
Image functions
IMAP, POP3 and NNTP functions
Informix functions
InterBase functions
Ingres II functions
IRC Gateway Functions
Java
LDAP functions
Mail functions
Mathematical Functions
Multi-Byte String Functions
MCAL functions
Mcrypt Encryption Functions
Mhash Functions
Microsoft SQL Server functions
Ming functions for Flash
Miscellaneous functions
mnoGoSearch Functions
mSQL functions
MySQL Functions
Network Functions
Unified ODBC functions
Oracle 8 functions
OpenSSL functions
Oracle functions
Ovrimos SQL functions
Output Control Functions
Object property and method call overloading
PDF functions
Verisign Payflow Pro functions
PHP options & information
POSIX functions
PostgreSQL functions
Program Execution functions
Printer functions
Pspell Functions
GNU Readline
GNU Recode functions
Regular Expression Functions (Perl-Compatible)
Regular Expression Functions (POSIX Extended)
Satellite CORBA client extension
Semaphore and Shared Memory Functions
SESAM database functions
Session handling functions
Shared Memory Functions
Shockwave Flash functions
SNMP functions
Socket functions
String functions
Sybase functions
URL Functions
Variable Functions
WDDX Functions
XML parser functions
XSLT functions
YAZ functions
YP/NIS Functions
Zip File Functions (Read Only Access)
Zlib Compression Functions

MyASPN >> Reference >> PHP Manual >> Function Reference
PHP Manual

XI. CURL, Client URL Library Functions

PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

In order to use the CURL functions you need to install the CURL package. PHP requires that you use CURL 7.0.2-beta or higher. PHP will not work with any version of CURL below version 7.0.2-beta.

To use PHP's CURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the "include" directory there should be a folder named "curl" which should contain the easy.h and curl.h files. There should be a file named "libcurl.a" located in the "lib" directory.

These functions have been added in PHP 4.0.2.

Once you've compiled PHP with CURL support, you can begin using the curl functions. The basic idea behind the CURL functions is that you initialize a CURL session using the curl_init(), then you can set all your options for the transfer via the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the CURL functions to fetch the PHP homepage into a file:

Example 1. Using PHP's CURL module to fetch the PHP homepage


<?php



$ch = curl_init ("http://www.php.net/");

$fp = fopen ("php_homepage.txt", "w");



curl_setopt ($ch, CURLOPT_FILE, $fp);

curl_setopt ($ch, CURLOPT_HEADER, 0);



curl_exec ($ch);

curl_close ($ch);

fclose ($fp);

?>

     

Table of Contents
curl_init -- Initialize a CURL session
curl_setopt -- Set an option for a CURL transfer
curl_exec -- Perform a CURL session
curl_close -- Close a CURL session
curl_version -- Return the current CURL version

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2003 ActiveState, a division of Sophos All rights reserved