HTTP POST Streaming

Yesterday I’ve been asked by a friend how we can easily http stream data from php. That was a really intersting question because it can be very useful in some case (e.g. when working with EDI). So I just made him a proof of concept.
I used socket to generate a POST HTTP request 

<?php
class PostRequest{
	//SERVER
	var $address;
	var $path;
	var $port;
	
	//XML
	var $xmlFile;
	
	//HTTP 
	var $boundary;
	
	
	
	function initRequest($addr, $p, $prt=80){
		$this->address = $addr;
		$this->path = $p;	
		$this->port = $prt;
		$this->boundary = md5("myString");
		
	}
	
	function setXML($x){
		$this->xmlFile = $x;
	}
	
	function send(){
	$fs = fsockopen($this->address, $this->port);
	if(!$fs){
		return false;	
		}
	else{
		$header ="POST ".$this->path." HTTP/1.0 200\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=".$this->boundary."\r\n\n";
		$this->body ="--".$this->boundary."\n
						Content-type: text/plain\n\n".$this->xmlFile."\n--".$this->boundary."\n";
						
		$request = $header.$this->body;
		
		
		fputs($fs,$request);
		fflush();
	fclose();
		return true;	
	
		}
	
	}



?>

I post the code but I will update it very soon since I’ve only made few test and I think it must be tweaked

Advertisements

2 Responses

  1. […] The proof of concepts blog my Dev playground « HTTP POST Streaming […]

  2. […] proof of concepts blog my Dev playground « HTTP POST Streaming NURVE – Public alpha release […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: