satishgaudo.com

Understanding technology

function to submit data via socket

/**
* sendDataOnSocket
* function to submit data via socket
* @param string $sContent content to send
* @param string $sHost Host name
* @param string $sFilePath  file to post data
* @param string $sMethod method name
* @return string aig response
* @access public
*/
public static function sendDataOnSocket($sContent,$sHost,$sFilePath,$sMethod) {
if(strlen($sHost)==0) {
return array(1, "Empty Host name");
}else if (strlen($sMethod)==0) {
return array(1, "Empty Method");
}
$fp = fsockopen($sHost, "80", $errno, $errstr, 30);
if (!$fp) {
//could not open socket
return array(1, "could not open socket");
} else {
$out = $sMethod." ".$sFilePath." HTTP/1.1\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: ".strlen($sContent)."\r\n";
$out .= "Host: $sHost:80\r\n";
$out .= $sContent;
$out .= "\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
$tempdata =  fgets($fp, 128);
$data .= $tempdata;
}
return array(0, $data);
}
}
Bookmark and Share
Categories: PHP
pidxfgop at 23:49 on 14 July 2009

thanks . i was searching for this code

lmn_nihez at 13:48 on 14 August 2009

Nice site.

gzb_lpnvo at 06:34 on 16 August 2009

Nice site.

imf_lltrl at 01:03 on 18 August 2009

Nice site.

njn_viqle at 12:49 on 21 August 2009

Nice site.

satishgaudo at 14:20 on 23 April 2010

$fp = fsockopen(”patterns.satishgaudo.com”, “80″, $errno, $errstr, 30);
if (!$fp) {
return false;
} else {
/* Case 1 Create collection */
$content = “action=mailnotification&rname=a&r_prc_id=4888115″;
$out = “POST /patterns.php HTTP/1.1\r\n”;
$out .= “Content-type: application/x-www-form-urlencoded\r\n”;
$out .= “Content-Length: “.strlen($content).”\r\n”;
$out .= “Host: patterns.satishgaudo.com:80\r\n”;
$out .= “Cookie: Rl=satish; rlo=satishgaudo; \r\n\r\n”;
$out .= $content;
$out .= “\r\n”;
fwrite($fp, $out);
while (!feof($fp))
{
$tempdata = fgets($fp, 128);
$data .= $tempdata;
}
echo $data;
}