<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LAMPlights &#187; thrift</title>
	<atom:link href="http://www.hermanradtke.com/blog/tag/thrift/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hermanradtke.com</link>
	<description>Personal anecdotes from my experiences using the LAMP stack</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:14:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Facebook Thrift PHP Client</title>
		<link>http://www.hermanradtke.com/blog/facebook-thrift-php-client/</link>
		<comments>http://www.hermanradtke.com/blog/facebook-thrift-php-client/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 22:27:20 +0000</pubDate>
		<dc:creator>Herman Radtke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[thrift]]></category>

		<guid isPermaLink="false">http://www.hermanradtke.com/blog/?p=273</guid>
		<description><![CDATA[A while back I wrote a post about using Facebook's Thrift.  One comment asked me to post the PHP client used to connect to the C++ server I was demo'ing.  Most of the client is boiler-plate code generated by Thrift, so I chose to omit it at the time.  Here it is: #!/usr/bin/env php &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote a post about using <a href="http://www.hermanradtke.com/blog/?p=52">Facebook's Thrift</a>.  One comment asked me to post the PHP client used to connect to the C++ server I was demo'ing.  Most of the client is boiler-plate code generated by Thrift, so I chose to omit it at the time.  Here it is:<br />
<span id="more-273"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/env php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'THRIFT_ROOT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/path/to/thrift'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'THRIFT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/Thrift.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'THRIFT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/protocol/TBinaryProtocol.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'THRIFT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/transport/TSocket.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'THRIFT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/transport/THttpClient.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'THRIFT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/transport/TBufferedTransport.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Sale.php'</span><span style="color: #339933;">;</span>
&nbsp;
try <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$socket</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TSocket<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9090</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$transport</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TBufferedTransport<span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$protocol</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TBinaryProtocol<span style="color: #009900;">&#40;</span><span style="color: #000088;">$transport</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SaleClient<span style="color: #009900;">&#40;</span><span style="color: #000088;">$protocol</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$transport</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Sale_deal<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dealno</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12345</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">term</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">payment</span> <span style="color: #339933;">=</span> <span style="color:#800080;">500.1</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">amtfin</span> <span style="color: #339933;">=</span> <span style="color:#800080;">1000.00</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Total cost: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">calc_apr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$transport</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>TException <span style="color: #000088;">$tx</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'TException: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$tx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.hermanradtke.com/blog/facebook-thrift-php-client/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

