Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

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 :

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. curl_exec ($ch);
  12. 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: , , , ,

Bookmark Post:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • NewsVine
  • Reddit
  • Netvouz
  • Spurl
  • Furl
  • digg
  • YahooMyWeb
  • del.icio.us

Posted in Uncategorized |

Related Posts

2 Responses

  1. How to solve file_get_contents and file() PHP errors » Quick PHP Code Tips and Examples Says:

    [...] work across servers which place restriction on file_get_contents() and file() function. The use of libcurlemu ensures that the script can work even on a server which doesn’t have the PHP CURL extension, which [...]

  2. php+curl+socks[4,5] може хтось шарить чого не паше - Форум Інтернет-кафе "Крапка" Says:

    Kramer auto Pingback[...] Допис від ivi ніяких ерорів. Поставив 5 php і все працює. з досвіду, заюзай http://phpcode.mypapit.net/php-class…rl-library/17/ [...]

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.