PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previouscrack_opendictcurl_closenext
Last updated: Tue, 09 Jul 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

XII. CURL

PHP supporte libcurl, une librairie cr��e par Daniel Stenberg, qui vous permet de vous connecter de communiquer avec de nombreux serveurs, gr�ce � de nombreux protocoles. libcurl supporte actuellement les protocoles suivants : http, https, ftp, gopher, telnet, dict, file, et ldap. libcurl supporte aussi les certificats HTTPS, les POST HTTP, PUT HTTP, le chargement par FTP (ce qui peut �tre fait par l'extension FTP), les chargement par formulaire HTTP, les proxies, les cookies et l'authentification par mot de passe et nom de compte.

Pour pouvoir utiliser les fonctions CURL, vous devez installer le package . PHP requiert la version CURL 7.0.2-beta ou plus r�cente. PHP ne fonctionnera pas avec une version inf�rieure � la version 7.0.2-beta.

Pour utiliser CURL depuis les scripts PHP, vous devez aussi compiler PHP avec l'option --with-curl[=DIR] o� DIR est le chemin jusqu'au dossier contenant les dossiers lib et include. Dans le dossier include il doit se trouver un dossier appel� curl, qui contient notamment les fichiers easy.h et curl.h. Il doit aussi se trouver un fichier nomm� libcurl.a dans le dossier lib.

Une fois que vous avez compil� PHP avec le support CURL, vous pouvez commencer � l'exploiter avec vos scripts PHP. Le principe de fonctionnement est d'initialiser une session CURL avec curl_init(), puis de choisir toutes vos options de transfert avec curl_exec() et de finir votre session avec curl_close(). Voici un exemple d'utilisation des fonctions CURL, qui r�cup�re la page principale de PHP :

Exemple 1. Utilisation de CURL et PHP pour r�cup�rer une page

<?php
$ch = curl_init ("http://www.php.net/");
$fp = fopen ("php_homepage.txt", "w");
curl_setopt ($ch, CURLOPT_INFILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
?>

Table des mati�res
curl_close -- Ferme une session CURL
curl_errno -- Return an integer containing the last error number
curl_error --  Return a string containing the last error for the current session
curl_exec -- Ex�cute une session CURL
curl_getinfo --  Get information regarding a specific transfer
curl_init -- Initialise une session CURL
curl_setopt -- Modifie une option de transfert CURL
curl_version -- Retourne la version courante de CURL
User Contributed Notes
CURL
add a note about notes
[email protected]
24-Aug-2000 11:01

For those of you looking for a win32 solution to get CURL to work, check out nice downloads set up for you to enable the CURL functions along with a number of others. (helped me out tremendously.)
[email protected]
09-Oct-2000 02:23

CURL seems to only allow you to download a remote file to a local file, then process it after the fact. It does not seem to allow for working on a file while it is being downloaded.
[email protected]
05-Nov-2000 12:42

To return the output into a variable set CURLOPT_RETURNTRANSFER to 1, so saith the php-dev list.
[email protected]
16-Dec-2000 01:31

For all u people that can't get CURL to work on Windows load the Dynamic Library by using:

dl("php_curl.dll");

if it says something like: can't use or load library files (or missing dllz), it's missing some DLL's like
php4ts.dll,SSLEAY32.dll,php_curl.dll,MSVCRT.dll locate these DLL's in your PHP binary and put them in your windows SYSTEM directory, i ectually found this out by editing the php_curl.dll file and looked for the DLL files its need (by searching for .dll) and just made sure that those files where accessible for by this DLL. This technique actually works for each dll :-) Look mommy i'm being a nerd :-)

Good luck,
Emile

[email protected]
17-Jan-2001 08:31

I used to download www pages to my script and one of the pages was different in MS explorer and different, when I downloaded it. Namely, information, I was really interested in was missing. That was because the server on the other bank of the river was looking at who is downloading the page. Everything got fixed when I pretended I was MSIE. It is done with curl. Here is a function, that you may use in similar situation

function download_pretending($url,$user_agent) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}

[email protected]
09-Feb-2001 09:57

There are undocumentated functions yet:

string curl_getinfo(int ch, int opt)
Get information regarding a specific transfer

supported options:
CURLINFO_EFFECTIVE_URL
CURLINFO_HTTP_CODE
CURLINFO_HEADER_SIZE
CURLINFO_REQUEST_SIZE
CURLINFO_TOTAL_TIME
CURLINFO_NAMELOOKUP_TIME
CURLINFO_CONNECT_TIME
CURLINFO_PRETRANSFER_TIME
CURLINFO_SIZE_UPLOAD
CURLINFO_SIZE_DOWNLOAD
CURLINFO_SPEED_DOWNLOAD
CURLINFO_SPEED_UPLOAD

[email protected]
09-Feb-2001 10:01

string curl_error(int ch)
Return a string contain the last error for the current session
int curl_errno(int ch)
Return an integer containing the last error number

the error codes are defined as constants in ../ext/curl/curl.c

[email protected]
27-May-2001 05:50

If you want to write your entire HTTP request without use any other CURL functions like CURLOPT_POST specify it within a curl_setopt ($ch,CURLOPT_CUSTOMREQUEST , $req) line;
Where $req looks like (let me imagine a POST request...):

POST /destination/script HTTP/1.1
Content-length: xxx
Content-type: text/xml
host: yourhost
accept: */*
accept-encoding: gzip, deflate
accept-language: en-us
connection: close; Keep-Alive
...
your POST data
...


CURLOPT_CUSTOMREQUEST is not documented?!? but it's useful and amazing!

marcomcc (Roma)

[email protected]
22-Sep-2001 10:22

The PHP 4.0.6 code contains some functions that are not documented on this page:



curl_getinfo(int ch) - Returns an associative array with detailed information about the last transfer, including the actual URL fetched, the HTTP response code, and the time taken to perform each phase of the transfer.



curl_error(int ch) - Returns a descriptive error string containing the last error code for the session.



curl_errno(int ch) - Returns an integer containing the last error number



Here is some output from curl_getinfo():



Array

(

[url] =>
>
[http_code] => 200

[header_size] => 261

[request_size] => 155

[filetime] => 0

[total_time] => 0.7408

[namelookup_time] => 0.031381

[connect_time] => 0.154251

[pretransfer_time] => 0.154589

[size_upload] => 0

[size_download] => 5612

[speed_download] => 3133.7556977376

[speed_upload] => 0

)

[email protected]
06-Jan-2002 01:12

In win32 (Windows 2000), I couldn't get apache to start with PHP/curl support 'cause it said it couldn't find the php_curl.dll. Well it was there.
MSVCRT.dll was there as well, but after I ran the dll through "Depends", there's a new DLL for the Microsoft .NET stuff. It's called msvcr70.dll, and without it, php_curl.dll won't load.
I didn't want to load .NET framework on my machine (which msdn.microsoft.com suggested)
I did a google search and found a downloadable copy of the file and threw it in my %system%\system32 folder and all the lights and whistles came on.

[email protected]
31-Jan-2002 01:47

in addition to the files named above, you should also add the file libeay32.dll to your PHP directory. The file can be found in the dlls directory
[email protected]
25-May-2002 06:30

NOTE:
There is a bug in cURL version 7.9.4 that can cause problems form posts.

I just spent a couple hours pulling my hair out over this.

I just upgraded to 7.9.7 and everything seems to work fine.

Here's a link to info on the cURL site.

[email protected]
22-Jun-2002 12:46

For an exaplanation of those Predefined Constants listed above see the following URL:


[email protected]
02-Jul-2002 03:18

Using the customrequest for a complete post is wrong. Libcurl will add a partial url, the http version and the standard headers after the post data - while this works with a non-persistent connection and an apache web server, it may fail under different conditions
loconet at hotmail dot com
05-Jul-2002 08:33

For those of you having problems loading php_curl.dll using Apache+PHP on Win32, try copying ssleay32.dll and libeay32.dll from the php/dlls directory to your php root directory.
snake @ bigfoot . com
11-Jul-2002 11:29

do not run the example snippet if you're using php 4.2.1 and libcurl 7.9.8 (or later versions i would assume); php.exe will crash even if you have the required DLLs in system32.

look at for some simple example code.

ibyte(at)SPAMISKILLEDnoxs.nl
25-Aug-2002 11:31

[Editors note]
Make sure that the supplied libeay32.dll and ssleay32.dll
(in the dlls-Folder) are on a path where PHP can find them.

A tip for Windows users (and possibly others): if you really can't get the cURL library (php_curl.dll) to work (like me), but you can get the precompiled command line utility (curl.exe) that's available from the cURL site to work, you can use PHP's system command execution facilities, like the backtick operator, to invoke cURL and obtain its output.

add a note about notes
previouscrack_opendictcurl_closenext
Last updated: Tue, 09 Jul 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Aug 31 06:19:44 2002 CEST