Technology Powered Knowledge Base
Click Here To Make FREE Audio & Video Call From Web Browser!

CURL and Real Time Implementations with PHP Applications

VN:F [1.9.22_1171]
Rating: +29 (from 29 votes)
VN:F [1.9.22_1171]
Rating: 10.0/10 (32 votes cast)

Modern PHP applications mostly depended on CURL, as we can do lots of thing with CURL. Mostly use of CURL is, creating communication gateway between different domains. With CURL we can grab any Web Page, can upload file with remote call to other webpage, can access FTP server with credential, we can parse data from one URL to another URL and many other uses are associated with CURL. PHP supports libcurl as native library.
 
It allows connecting and communicating with many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. Current version also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, and user authentication.
 

Develop with PHP CURL
Here we can describe common and useful functions and parameters of CURL; some other functions and parameters also there. To know more about it please visit, http://www.php.net/manual/en/book.curl.php
1) Create a new reference with CUL so that libcurl will initiate a new instance, we use curl_init() for this purpose.
2) Setup various operations like, set remote URl, set POST /GET data, FTP operations, Cookie store, Proxy connections, Secure connection etc. for this purpose we use curl_setopt() function.
3) We need to execute CURL with previously setup parameters, and in this stage we will get return data as a string. curl_exec() function is useful for this step.
4) We need to close instance as otherwise it will wastage our instance. curl_close is the function for close CURL instace.
 

Simple Example of CURL


<?php
//create a new reference
$obcurl=curl_init();
//set up options
curl_setopt($obcurl, CURLOPT_URL, "http://www.santanu.net");
curl_setopt($obcurl, CURLOPT_HEADER, 0);
//execute operations and get return
$return=curl_exec($obcurl);
//close the reference
curl_close($obcurl);

//display return string
echo $return;
?>

We can initiate multiple curl instances with single functions, curl_ multi_ init(), curl_ multi_ exec(), curl_ multi_ close() etc function we can use for this purpose.
 
For curl_setopt() function, there are lots of parameters we can use for various operations. As example, CURLOPT_URL is necessary parameter to setup remote URl where actual operation we need to do, CURLOPT_POST is useful when we need to post data over HTTP, we can upload a file using CURLOPT_UPLOAD parameter, CURLOPT_USERPWD we can use to authenticate with username & password, CURLOPT_PROXY can be useful for setup a proxy connection. For operation with FTP CURLOPT_FTPPORT is useful parameter to set FTP port. So many other operations also associated with CURL.
  
Some other useful options are, CURLOPT_SSL_VERIFYPEER, CURLOPT_TRANSFERTEXT, CURLOPT_FTPSSLAUTH, CURLOPT_HTTPAUTH, CURLOPT_PROTOCOLS, CURLOPT_PORT, CURLOPT_PROXYAUTH, CURLOPT_PROXYPORT, CURLOPT_PROXYTYPE, CURLOPT_SSL_VERIFYHOST, CURLOPT_SSLVERSION, CURLOPT_TIMEOUT, CURLOPT_COOKIE, CURLOPT_COOKIEFILE, CURLOPT_COOKIEJAR, CURLOPT_ENCODING, CURLOPT_PROXYUSERPWD, CURLOPT_REFERER, CURLOPT_SSLCERT, CURLOPT_SSLCERTPASSWD, CURLOPT_SSLKEY, CURLOPT_USERAGENT, CURLOPT_HTTPHEADER, CURLOPT_HEADERFUNCTION etc.

CURL and Real Time Implementations with PHP Applications, 10.0 out of 10 based on 32 ratings



Sign Up     Sign In