cURL basics and functions over view
cURL is a PHP library which allows you to connect and communicate to many different types of servers with many different types of protocols.Main difference is it has session capability unlik fopen. We can make small scale robot script with cURL functions in PHP.
With cURL we can:
- Implement payment gateways’ payment notification scripts.
- Download and upload files from remote servers.
- Login to other websites and access members only sections.
- Cross site communication with PHP backend and Ajax.
PHP cURL library is definitely the odd man out. Unlike other PHP libraries where a whole plethora of functions is made available, PHP cURL wraps up a major parts of its functionality with following functions.
Curl functions are:
- curl_close — Close a cURL session
- curl_copy_handle — Copy a cURL handle along with all of its preferences
- curl_errno — Return the last error number
- curl_error — Return a string containing the last error for the current session
- curl_exec — Perform a cURL session
- curl_getinfo — Get information regarding a specific transfer
- curl_init — Initialize a cURL session
- curl_multi_add_handle — Add a normal cURL handle to a cURL multi handle
- curl_multi_close — Close a set of cURL handles
- curl_multi_exec — Run the sub-connections of the current cURL handle
- curl_multi_getcontent — Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set
- curl_multi_info_read — Get information about the current transfers
- curl_multi_init — Returns a new cURL multi handle
- curl_multi_remove_handle — Remove a multi handle from a set of cURL handles
- curl_multi_select — Wait for activity on any curl_multi connection
- curl_setopt_array — Set multiple options for a cURL transfer
- curl_setopt — Set an option for a cURL transfer
- curl_version — Gets cURL version information
curl_setopt is the pivot around which the main cURL functionality revolves. cURL functioning is controlled by way of passing predefined options and values to this function.
A simple example to handle google rss feed
/* * * Initialize the cURL session */ $curl_handler = curl_init(); /* * * Set the URL of the page or file to download. */ curl_setopt($curl_handler, CURLOPT_URL, 'http://news.google.com/news?hl=en&topic=t&output=rss'); /* * * Ask cURL to return the contents in a variable * instead of simply echoing them to the browser. */ curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, 1); /* * * Execute the cURL session,do some stuff with content */ $contents = curl_exec ($curl_handler); /* * * Close cURL session, *be sure to close the handler as curl stores cookies ,other file data stores on server. */ curl_close ($curl_handler);
In the above example we used CURLOPT_URL,CURLOPT_RETURNTRANSFER options.
Popularity: 10% [?]









Related Articles
2 users responded in this post
[...] learned some basics in my previous article cURL basics. Here we cover a topic how to submit a form to remote [...]
[...] Excerpt from: php curl basic reference | Php Development [...]
Leave A Reply