note 68815 added to function.socket-read

From: Date: Fri, 11 Aug 2006 18:28:48 +0000
Subject: note 68815 added to function.socket-read
Groups: php.notes 
Request: Send a blank email to php-notes+get-115806@lists.php.net to get a copy of this message
Interesting use of sockets: <?php //Use sockets and xml coool!!! //Check this out /* //============================================================ //First you create a xsl template like the following called test.xsl: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="iso-8859-1"/> <xsl:template match="/"> <table> <tr><td><font color='red'><xsl:value-of select="test/one"/></font></td></tr> <tr><td><font color='blue'><xsl:value-of select="test/two"/></font></td></tr> </table> </xsl:template> </xsl:stylesheet> //============================================================ */ //============================================================ //Second: You create a php script called getResponse.php with the following content: echo chr(60).chr(63)."xml version".chr(61)."\"1.0\" encoding".chr(61)."\"ISO".chr(45)."8859".chr(45)."1\" standalone".chr(61)."\"yes\" ".chr(63).chr(62)."\n"; ...connect to a database postgres... $sql = "select first, second from my_table;"; ...execute the query and asign to $result array... $xml_string = "<test>\n"; while($result){ $xml_string .= "<one>".$result[0]['first']."</one>\n"; $xml_string .= "<two>".$result[0]['second']."</two>\n"; } $xml_string .= "</test>\n"; header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Content-Type:text/xml"); echo $xml_string; //============================================================ //==================S O C K E T S=============================== //Finally: Create a php script called master.php with the following content. $server = "192.168.0.1"; //my server $sk = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_connect($sk, $server, 80); $request = "GET /getResponse.php HTTP/1.0"."\r\n"; $request .= "Host:192.168.0.1 \r\n\r\n"; socket_write($sk, $request); $doc = new DOMDocument(); $xsl = new XSLTProcessor(); $doc->load("./test.xsl"); $xsl->importStyleSheet($doc); $doc->loadXML(strstr(socket_read($sk,12000),"<?xml")); echo $xsl->transformToXML($doc); //==================S O C K E T S================================ "The output is the result of the query one line red and one blue". //The most interesting thing here, is that you can create all the //pages of your site with one xsl template and xml, but with //the advantage of using the power of PHP. //cool isn't it? Regards bazz. ?> ---- Server IP: 148.206.80.9 Probable Submitter: 200.66.106.217 (proxied: 192.168.0.3) ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.socket-read.php Edit -- https://master.php.net/note/edit/68815 Del: integrated -- https://master.php.net/note/delete/68815/integrated Del: useless -- https://master.php.net/note/delete/68815/useless Del: bad code -- https://master.php.net/note/delete/68815/bad+code Del: spam -- https://master.php.net/note/delete/68815/spam Del: non-english -- https://master.php.net/note/delete/68815/non-english Del: in docs -- https://master.php.net/note/delete/68815/in+docs Del: other reasons-- https://master.php.net/note/delete/68815 Reject -- https://master.php.net/note/reject/68815 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115806) next »