lundi 9 juillet 2007

!php curl library

Libcurlemu : a drop-in replacement for php curl library
March 16th, 2007 by Jon Moffet

libcurl or php curl extension is a flexible multiprotocol client library widely in use in various PHP scripts. It can be use to access FTP,HTTP,HTTPS,DICT,TELNET,SCP and LDAP protocol.

libcurl is popular among PHP programmers because it support various HTTP methods which can be use to create web robot, crawler and auto-submitters by emulating a web browser.

However for various reasons, some web hosting company choose not to install php-curl extension and this will affect your php scripts which uses curl_* functions.

Solution :
To solve that problem, you can download and use libcurlemu, a pure PHP implementation of libcurl. By using this library, your php scripts is guaranteed to run regardless if php curl extension is installed or otherwise.

Adapting your scripts to php curl is simple, you only need to include "libcurlemu.inc.php" in your scripts, and everything will run as if the server has php curl installed. There are no further modifications required to use libcurlemu.

Example :
PLAIN TEXT
PHP:

1.
// first, include libcurlemu.inc.php
2.
require_once('libcurlemu.inc.php');
3.

4.
//... the rest of your scripts is under here, unmodified
5.
$ch = curl_init();
6.

7.
curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml");
8.
curl_setopt($ch, CURLOPT_POST, 1);
9.
curl_setopt($ch, CURLOPT_POSTFIELDS,
10.
"postvar1=value1&postvar2=value2);
11.
12.
curl_exec ($ch);
13.
curl_close ($ch);

libcurlemu will attempt to use the native PHP Curl extension before it switches to its own library, this will ensure that your scripts will run portably without any further modification when you ported it to a server with PHP curl extensions installed.

Tags: php, curl, libcurl, library, extensions

Aucun commentaire: