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.

  <?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);
?>