Showing posts with label Curl. Show all posts
Showing posts with label Curl. Show all posts
Post data to a specific port using PHP/Curl.
Posted by Raj
Post data to a specific port using PHP/Curl.
In this article,I will show how to Post data to a specific port using PHP/Curl Method. PHP-curl library can be used to communicate with a specific port under Linux and windows platform.
Example: Send data to Port in PHP.
In this article,I will show how to Post data to a specific port using PHP/Curl Method. PHP-curl library can be used to communicate with a specific port under Linux and windows platform.
Example: Send data to Port in PHP.
<?php
ini_set("display_errors",1);
error_reporting(E_ERROR);
$msg="&command=1";
$url = "http://127.0.0.1:1234";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $msg);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
if($response!="")
{
$fp = fopen("test.txt","w");
fwrite( $fp, $response);
fclose($fp);
}
curl_close($curl);
?>
Difference between curl and file_get_contents
Posted by Raj
Difference between curl and file_get_contents
In this tutorial,I will explain difference between curl and file_get_contents.
PHP offers two main options to get a remote file, curl and file_get_contents. There are many difference between the two.
file_get_contents - It is a function to get the contents of a file
curl - It is a library.curl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies.
file_get_contents() for a remote file, it is very slow, and does not handle redirects, caching, cookies.
Curl is a much faster alternative to file_get_contents.
In this tutorial,I will explain difference between curl and file_get_contents.
PHP offers two main options to get a remote file, curl and file_get_contents. There are many difference between the two.
file_get_contents - It is a function to get the contents of a file
curl - It is a library.curl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies.
file_get_contents() for a remote file, it is very slow, and does not handle redirects, caching, cookies.
Curl is a much faster alternative to file_get_contents.
cURL Simple Example in PHP
Posted by Raj
cURL Simple Example in PHP:
cURL allows you to connect and communicate to many different types of servers with many different types of protocols.
PHP Supports libcurl.
Example:
<?php
// initialize curl session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com"); // set url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//return the transfer as a string
$output = curl_exec($ch);//output string
// close curl session
curl_close($ch);
?>
cURL allows you to connect and communicate to many different types of servers with many different types of protocols.
PHP Supports libcurl.
Example:
<?php
// initialize curl session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com"); // set url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//return the transfer as a string
$output = curl_exec($ch);//output string
// close curl session
curl_close($ch);
?>
What is cURL in PHP?
Posted by Raj
What is cURL in PHP?
cURL allows you to connect and communicate to many different types of servers with many different types of protocols.
PHP Supports libcurl.
Requirements:
In order to use PHP's cURL functions you need to install the libcurl package.PHP 5.0.0 requires a libcurl version 7.10.5 or greater.
cURL Functions:
curl_close : Close a cURL session.
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_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 allows you to connect and communicate to many different types of servers with many different types of protocols.
PHP Supports libcurl.
Requirements:
In order to use PHP's cURL functions you need to install the libcurl package.PHP 5.0.0 requires a libcurl version 7.10.5 or greater.
cURL Functions:
curl_close : Close a cURL session.
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_setopt_array: Set multiple options for a cURL transfer.
curl_setopt: Set an option for a cURL transfer.
curl_version: Gets cURL version information.