<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿Tim日志]]></title> 
<link>https://atim.cn/index.php</link> 
<description><![CDATA[专业的php开发者.开发团队的带队人]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿Tim日志]]></copyright>
<item>
<link>https://atim.cn/post//</link>
<title><![CDATA[PHP程序与服务器端通讯方法小结]]></title> 
<author>bkkkd &lt;partybase@gmail.com&gt;</author>
<category><![CDATA[开发应用]]></category>
<pubDate>Mon, 06 Feb 2006 10:44:33 +0000</pubDate> 
<guid>https://atim.cn/post//</guid> 
<description>
<![CDATA[ 
	   假设有10个网站，分布在各地，它们的库存要同步，而数据库不支持远程连接。<br /><br />　　我们要实时地取得服务器的库存数，可以通过很多种方法，我所知道的有以下几种：<br /><br />　　　·CURL方式<br /><br />　　　·SOCKET方式<br /><br />　　　·PHP5中的SOAP方式<br /><br />　　以下分别给出示例来实现它：<br /><br />　　CURL方式<br /><br />　　client.php<br /><br /><code>＜?php<br />$psecode = ’NDE005’;<br />$website = ’www.abc.com’;<br />$amt = 1;<br />$pwd = 123456;<br />$ch = curl_init();<br />$curl_url = &quot;http://ics1.server.com/index.php?web=&quot; . $website . <br />&quot;&amp;pwd=&quot; . $pwd . &quot;&amp;action=check&amp;pseid=&quot; . $psecode . <br />&quot;&amp;amt=&quot; . $amt;<br />curl_setopt($ch, CURLOPT_URL, $curl_url);<br />curl_setopt($ch, CURLOPT_POST, 1);<br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//不直接输出，返回到变量<br />$curl_result = curl_exec($ch);<br />$result = explode(’,’, $curl_result);<br />curl_close($ch);<br />print_r($result);<br />?＞</code><br />　　服务器端只需按一定的格式输出，然后客户端按此格式接收就可以了如：<br /><br /><code>echo &quot;OK,&quot; . $fpsecode . &quot;,&quot; . $fbalance ;//以逗号分隔</code><br />　　SOCKET方式<br /><br />　　这个要借助第三方类库HttpClient,可以到这里下载：http://scripts.incutio.com/httpclient/<br /><br /><code>＜?php<br />require_once ’class/HttpClient.php’;<br />$params = array(’web’ =＞ ’www.abc.com’,<br />’pwd’ =＞ ’123456’,<br />’action’ =＞ ’check’,<br />’pseid’ =＞ ’NDE005’,<br />’amt’ =＞ 1);<br />$pageContents = HttpClient::quickPost(’http://ics.server.com/index.php’, $params);<br />$result = explode(’,’, $pageContents);<br />print_r($result);<br />?＞</code><br />　　PHP5中的SOAP方式<br /><br />　　server.php<br /><br /><code>＜?php <br />function getQuote($fpsecode) &#123; <br />global $dbh;<br />$result = array();<br />try &#123;<br />$query = &quot;SELECT fprice, fcansale, fbalance, fbaltip FROM tblbalance where upper(trim(fpsecode)) = :psecode limit 1&quot;;<br />$stmt = $dbh-＞prepare($query);<br />$stmt-＞execute(array(’:psecode’ =＞ strtoupper(trim($fpsecode))));<br />$stmt-＞bindColumn(’fprice’, $fprice);<br />$stmt-＞bindColumn(’fcansale’, $fcansale);<br />$stmt-＞bindColumn(’fbalance’, $fbalance);<br />$stmt-＞bindColumn(’fbaltip’, $fbaltip);<br />while($row = $stmt-＞fetch(PDO_FETCH_BOUND)) &#123;<br />//<br />&#125;<br />&#125; catch (PDOException $e) &#123;<br />echo $e-＞getMessage();<br />&#125;<br />return $fprice; //你可以返回一个数组<br />&#125; <br /><br />$dsn = ’pgsql:host=192.168.*.* port=5432 dbname=db user=123456 password=123456’;<br />try &#123;<br />$dbh = new PDO($dsn);<br />&#125; catch (PDOException $e) &#123;<br />die(’Connection failed: ’ . $e-＞getMessage()); <br />&#125;<br />ini_set(&quot;soap.wsdl_cache_enabled&quot;, &quot;0&quot;); // disabling WSDL cache <br />$server = new SoapServer(&quot;stockquote.wsdl&quot;); //配置文件<br />$server-＞addFunction(&quot;getQuote&quot;); <br />$server-＞handle(); <br />?＞</code><br />　　stockquote.wsdl<br /><br /><code>＜?xml version =’1.0’ encoding =’UTF-8’ ?＞ <br />＜definitions name=’StockQuote’ <br />targetNamespace=’http://example.org/StockQuote’ <br />xmlns:tns=’ http://example.org/StockQuote ’ <br />xmlns:soap=’http://schemas.xmlsoap.org/wsdl/soap/’ <br />xmlns:xsd=’http://www.w3.org/2001/XMLSchema’ <br />xmlns:soapenc=’http://schemas.xmlsoap.org/soap/encoding/’ <br />xmlns:wsdl=’http://schemas.xmlsoap.org/wsdl/’ <br />xmlns=’http://schemas.xmlsoap.org/wsdl/’＞ <br /><br />＜message name=’getQuoteRequest’＞ <br />＜part name=’symbol’ type=’xsd:string’/＞ <br />＜/message＞ <br />＜message name=’getQuoteResponse’＞ <br />＜part name=’Result’ type=’xsd:float’/＞ <br />＜/message＞ <br /><br />＜portType name=’StockQuotePortType’＞ <br />＜operation name=’getQuote’＞ <br />＜input message=’tns:getQuoteRequest’/＞ <br />＜output message=’tns:getQuoteResponse’/＞ <br />＜/operation＞ <br />＜/portType＞ <br /><br />＜binding name=’StockQuoteBinding’ type=’tns:StockQuotePortType’＞ <br />＜soap:binding style=’rpc’ <br />transport=’http://schemas.xmlsoap.org/soap/http’/＞ <br />＜operation name=’getQuote’＞ <br />＜soap:operation soapAction=’urn:xmethods-delayed-quotes#getQuote’/＞ <br />＜input＞ <br />＜soap:body use=’encoded’ namespace=’urn:xmethods-delayed-quotes’ <br />encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/＞ <br />＜/input＞ <br />＜output＞ <br />＜soap:body use=’encoded’ namespace=’urn:xmethods-delayed-quotes’ <br />encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/＞ <br />＜/output＞ <br />＜/operation＞ <br />＜/binding＞ <br /><br />＜service name=’StockQuoteService’＞ <br />＜port name=’StockQuotePort’ binding=’StockQuoteBinding’＞ <br />＜soap:address location=’http://192.168.3.9/php5/server.php’/＞ <br />＜/port＞ <br />＜/service＞ <br />＜/definitions＞<br /><br />client.php<br /><br />＜?php <br />$client = new SoapClient(&quot;stockquote.wsdl&quot;); <br />$result = $client-＞getQuote(&quot;nde005&quot;); <br />print_r($result);<br />?＞</code>
]]>
</description>
</item><item>
<link>https://atim.cn/post//#blogcomment</link>
<title><![CDATA[[评论] PHP程序与服务器端通讯方法小结]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://atim.cn/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>