Both the XML and PHP output from Dream services contain the same data; the only difference is in the format. The documentation on OpenGarden assumes XML output. In general you can assume these rules:

  • There will be one top level object containing the response.
  • Simple XML elements (elements that contain only content) become string/value pairs.
  • Complex XML elements (elements that contain nested elements) become nested arrays with keys.
  • Attributes become string/value pairs.
  • If an element contains both content and attributes, the attributes become string/value pairs and the content becomes a string/value pair with the name "content."
  • Repeated elements map onto arrays with indexes. The array is named after the element. The values of the array depend on the content of the repeated elements, that is, simple content becomes simple values, nested elements become arrays with keys. Note, however, that if a particular response that normally contains repeated element contains only one element you will not get an array of one element in the PHP output -- the element is treated as if it were a simple complex XML element. For repeated elements you should ensure you test for an array or a scalar value.

Getting Serialized PHP Output with "dream.out.format=php"

By default all data exchanges with Dream services use XML.  However, an XML response can be automatically converted to serialized PHP by using the dream.out.format=php parameter in the request URI:

http://dreamserver/stats/record/RESPONSE_TIME&dream.out.format=php

Sample Xml

GET http://dreamserver/stats/record/stat1


<stat>
	<name>stat1</name>
	<source>http://localhost:8081/stats/record/stat1/</source>
	<service>http://localhost:8081/stats/</service>
	<min>0</min>
	<max>9.594</max>
	<avg>4.914</avg>
	<var>0.14535147392290246</var>
	<sum>49.14</sum>
	<count>10</count>
	<first>2006-05-17T00:26:36.6098976-07:00</first>
	<last>2006-05-17T00:42:27.4853392-07:00</last>
	<rate>95.08754416</rate>
	<ratevar>0.99909449928635941</ratevar>
</stat>

Sample Serialized PHP

GET http://dreamserver/stats/record/stat...out.format=php


a:1:{s:4:"stat";a:13:{s:4:"name";s:5:"stat1";s:6:"source";s:41:"http://localhost:8081/stats/record/stat1/";s:7:"service";s:28:"http://localhost:8081/stats/";s:3:"min";s:1:"0";s:3:"max";s:5:"9.594";s:7:"average";s:5:"4.914";s:8:"variance";s:19:"0.14535147392290246";s:3:"sum";s:5:"49.14";s:5:"count";s:2:"10";s:5:"first";s:33:"2006-05-17T00:26:36.6098976-07:00";s:4:"last";s:33:"2006-05-17T00:42:27.4853392-07:00";s:4:"rate";s:11:"95.08754416";s:7:"ratevar";s:19:"0.99909449928635941";}}

Sample PHP Object

The serialized PHP output can be converted into a PHP object by using the built-in unserialize() function.

Array(
	[stat] => Array(
		[name] => "stat1" 
		[source] => "http://localhost:8081/stats/record/stat1/" 
		[service] => "http://localhost:8081/stats/" 
		[min] => "0" 
		[max] => "9.594" 
		[average] => "4.914" 
		[variance] => "0.14535147392290246" 
		[sum] => "49.14" 
		[count] => "10" 
		[first] => "2006-05-17T00:26:36.6098976-07:00" 
		[last] => "2006-05-17T00:42:27.4853392-07:00" 
		[rate] => "95.08754416" 
		[ratevar] => "0.99909449928635941" 
	) 
)
Tag page
You must login to post a comment.