Using cURL with PHP and Scriptol
cURL is a library for transferring files over the Internet or other network, to send or receive them under all existing protocols (http, ftp, ldap).
Is an alternative to fsockopen. It is implemented in PHP and usable in C and C++.
Testing the availability of cURL on a web hosting
Phpinfo() displays active modules on a server.
Install the following script on your hosting:
<?php echo phpinfo();?>
If cURL is enabled, a table like this will be displayed:
Enabling cURL in a local server (Xampp for example)
cURL is not enabled by default, it must be done manually. The menu has a command to do this, but it acts only on the configuration of PHP within the Apache directory.
An installation of PHP is included in the local server and we must change the file PHP.INI in both:
The following line must be uncommented in both:
Check that you have the libeay32.dll and ssleay32.dll modules.
An interface to the PHP functions is available in the archive (see at bottom of page):
dyn curl_init(cstring curlopt = null)
boolean curl_setopt(dyn, int, dyn)
constant int CURLOPT_URL // pass URL
constant int CURLOPT_CONNECTTIMEOUT // limit waiting time forever
constant int CURLOPT_UPLOAD // send file
There are many other variables that you have to define yourselves according to your needs with lines as this:
constant int CURLOPT_xxx
Two scripts are included in the archive:
curl-check.sol: checks the availability of cURL, displays the version and features.
curl-demo.sol: reads an RSS feed on a remote server.
We use cURL by opening a session with curl_init() and indicating the type of transaction to achieve with curl_setopt().
curl_exec () starts the execution and the session is closed with curl_close().
The PHP manual describes with examples the use of cURL and shows all possible options.
Using cURL with the RSS reader
As it appeared in the forum, sometimes the server in a shared hosting does not allow access to another site, and if we want to integrate an RSS feed, which is impossible with DOMDocument-> load or fsockopen becomes possible with cURL.
We replace this line in the function RSS_retrieve:
$hnd = curl_init();
curl_setopt($hnd, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($hnd, CURLOPT_URL, $url);
$data = curl_exec($hnd);
See RSS reader.