2 /* CURL Extension Emulation Library
4 * Copyright 2004-2005, Steve Blinch
5 * http://code.blitzaffe.com
6 * ============================================================================
10 * Provides a pure-PHP implementation of the PHP CURL extension, for use on
11 * systems which do not already have the CURL extension installed. It emulates
12 * all of the curl_* functions normally provided by the CURL extension itself.
14 * This will automatically detect and use the best CURL implementation available
15 * on your server. It will attempt the following, in order:
17 * 1) Check for the existence of the "real" CURL PHP Extension. If it is
18 * loaded, the library will do nothing (and it will not interfere with the
20 * 2) Check for the existence of the CURL console binary (usually located in
21 * /usr/bin/curl). If found, the library will emulate the CURL PHP
22 * extension (including all curl_* functions) and use the console binary
23 * to execute all requests.
24 * 3) If neither the "real" CURL PHP Extension nor the CURL console binary
25 * are available, the library will emulate the CURL PHP extension (including
26 * all curl_* functions) using a native, pure-PHP HTTP client implementation.
27 * This implementation is somewhat limited, but it provides support for most
28 * of the common CURL options. HTTPS (SSL) support is available in this
29 * mode under PHP 4.3.0 if the OpenSSL Extension is loaded.
31 * Thus, by including this library in your project, you can rely on having some
32 * level of CURL support regardless of the configuration of the server on which
38 * Simply copy all of the libcurlemu files into your project directory, then:
40 * require_once("libcurlemu.inc.php");
42 * After this, you can use all of the curl_* functions documented in the PHP
48 * // CURL Extension Emulation Library Example
50 * // Usage should be straightforward; you simply use this script exactly as you
51 * // would normally use the PHP CURL extension functions.
53 * // first, include libcurlemu.inc.php
54 * require_once('libcurlemu.inc.php');
56 * // at this point, libcurlemu has detected the best available CURL solution
57 * // (either the CURL extension, if available, or the CURL commandline binary,
58 * // if available, or as a last resort, HTTPRetriever, our native-PHP HTTP
59 * // client implementation) and has implemented the curl_* functions if
60 * // necessary, so you can use CURL normally and safely assume that all CURL
61 * // functions are available.
63 * // the rest of this example code is copied straight from the PHP manual's
64 * // reference for the curl_init() function, and will work fine with libcurlemu
66 * // create a new CURL resource
69 * // set URL and other appropriate options
70 * curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
71 * curl_setopt($ch, CURLOPT_HEADER, false);
73 * // grab URL and pass it to the browser
76 * // close CURL resource, and free up system resources
82 * This script is free software; you can redistribute it and/or modify it under the
83 * terms of the GNU General Public License as published by the Free Software
84 * Foundation; either version 2 of the License, or (at your option) any later
87 * This script is distributed in the hope that it will be useful, but WITHOUT ANY
88 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
89 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
92 * You should have received a copy of the GNU General Public License along
93 * with this script; if not, write to the Free Software Foundation, Inc.,
94 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
96 if (!extension_loaded('curl') && !function_exists('curl_init')) {
97 define('CURLEXT_MISSING_ABORT',true);
98 require_once(dirname(__FILE__
)."/libcurlexternal.inc.php");
100 if (!function_exists('curl_init')) {
101 require_once(dirname(__FILE__
)."/class_HTTPRetriever.php");
102 require_once(dirname(__FILE__
)."/libcurlnative.inc.php");