国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

PHP程序與服務(wù)器端通訊方法小結(jié)

瀏覽:5日期:2024-02-03 10:44:33

假設(shè)有10個(gè)網(wǎng)站,分布在各地,它們的庫(kù)存要同步,而數(shù)據(jù)庫(kù)不支持遠(yuǎn)程連接。

我們要實(shí)時(shí)地取得服務(wù)器的庫(kù)存數(shù),可以通過(guò)很多種方法,我所知道的有以下幾種:

 ·CURL方式

 ·SOCKET方式

 ·PHP5中的SOAP方式

以下分別給出示例來(lái)實(shí)現(xiàn)它:

CURL方式

client.php

<?php$psecode = ’NDE005’;$website = ’www.abc.com’;$amt = 1;$pwd = 123456;$ch = curl_init();$curl_url = 'http://ics1.server.com/index.php?web=' . $website . '&pwd=' . $pwd . '&action=check&pseid=' . $psecode . '&amt=' . $amt;curl_setopt($ch, CURLOPT_URL, $curl_url);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//不直接輸出,返回到變量$curl_result = curl_exec($ch);$result = explode(’,’, $curl_result);curl_close($ch);print_r($result);?>

服務(wù)器端只需按一定的格式輸出,然后客戶端按此格式接收就可以了如:

echo 'OK,' . $fpsecode . ',' . $fbalance ;//以逗號(hào)分隔

SOCKET方式

這個(gè)要借助第三方類庫(kù)HttpClient,可以到這里下載:http://scripts.incutio.com/httpclient/

<?phprequire_once ’class/HttpClient.php’;$params = array(’web’ => ’www.abc.com’,’pwd’ => ’123456’,’action’ => ’check’,’pseid’ => ’NDE005’,’amt’ => 1);$pageContents = HttpClient::quickPost(’http://ics.server.com/index.php’, $params);$result = explode(’,’, $pageContents);print_r($result);?>

PHP5中的SOAP方式

server.php

<?php function getQuote($fpsecode) { global $dbh;$result = array();try {$query = 'SELECT fprice, fcansale, fbalance, fbaltip FROM tblbalance where upper(trim(fpsecode)) = :psecode limit 1';$stmt = $dbh->prepare($query);$stmt->execute(array(’:psecode’ => strtoupper(trim($fpsecode))));$stmt->bindColumn(’fprice’, $fprice);$stmt->bindColumn(’fcansale’, $fcansale);$stmt->bindColumn(’fbalance’, $fbalance);$stmt->bindColumn(’fbaltip’, $fbaltip);while($row = $stmt->fetch(PDO_FETCH_BOUND)) {//}} catch (PDOException $e) {echo $e->getMessage();}return $fprice; //你可以返回一個(gè)數(shù)組}

$dsn = ’pgsql:host=192.168.*.* port=5432 dbname=db user=123456 password=123456’;try {$dbh = new PDO($dsn);} catch (PDOException $e) {die(’Connection failed: ’ . $e->getMessage()); }ini_set('soap.wsdl_cache_enabled', '0'); // disabling WSDL cache $server = new SoapServer('stockquote.wsdl'); //配置文件$server->addFunction('getQuote'); $server->handle(); ?>

stockquote.wsdl

<?xml version =’1.0’ encoding =’UTF-8’ ?> <definitions name=’StockQuote’ targetNamespace=’http://example.org/StockQuote’ xmlns:tns=’ http://example.org/StockQuote ’ xmlns:soap=’http://schemas.xmlsoap.org/wsdl/soap/’ xmlns:xsd=’http://www.w3.org/2001/XMLSchema’ xmlns:soapenc=’http://schemas.xmlsoap.org/soap/encoding/’ xmlns:wsdl=’http://schemas.xmlsoap.org/wsdl/’ xmlns=’http://schemas.xmlsoap.org/wsdl/’>

<message name=’getQuoteRequest’> <part name=’symbol’ type=’xsd:string’/> </message> <message name=’getQuoteResponse’> <part name=’Result’ type=’xsd:float’/> </message>

<portType name=’StockQuotePortType’> <o(jì)peration name=’getQuote’> <input message=’tns:getQuoteRequest’/> <o(jì)utput message=’tns:getQuoteResponse’/> </operation> </portType>

<binding name=’StockQuoteBinding’ type=’tns:StockQuotePortType’> <soap:binding style=’rpc’ transport=’http://schemas.xmlsoap.org/soap/http’/> <o(jì)peration name=’getQuote’> <soap:operation soapAction=’urn:xmethods-delayed-quotes#getQuote’/> <input> <soap:body use=’encoded’ namespace=’urn:xmethods-delayed-quotes’ encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/> </input> <o(jì)utput> <soap:body use=’encoded’ namespace=’urn:xmethods-delayed-quotes’ encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/> </output> </operation> </binding>

<service name=’StockQuoteService’> <port name=’StockQuotePort’ binding=’StockQuoteBinding’> <soap:address location=’http://192.168.3.9/php5/server.php’/> </port> </service> </definitions>

client.php

<?php $client = new SoapClient('stockquote.wsdl'); $result = $client->getQuote('nde005'); print_r($result);?>

標(biāo)簽: PHP
主站蜘蛛池模板: 国产片18在线观看 | 日韩 国产 欧美 精品 在线 | 在线精品亚洲欧洲第一页 | 欧美高清另类自拍视频在线看 | 免费一级网站免费 | 国产麻豆一级在线观看 | 欧美一级免费看 | 日本视频免费在线播放 | 久久精品大片 | 在线日韩中文字幕 | 免费一级欧美片在线观免看 | 国产精品久久久香蕉 | 久久中文亚洲国产 | 欧美韩国日本 | 中文字幕无线精品乱码一区 | 国产亚洲精品久久久久久久 | 美女被免费网站视频软件 | 曰本黄大片 | 国产综合久久久久 | 在线欧美一级毛片免费观看 | 91刘亦菲精品福利在线 | 黄色a三级免费看 | 69交性视频| 久久怡红院 | 欧美成人视屏 | 怡红院在线视频全部观看 | 在线视频 自拍 | 亚洲素人在线 | 成年男女的免费视频网站 | 欧美男女网站 | 性欧美精品孕妇 | 中国成人免费视频 | 一级白嫩美女毛片免费 | 亚洲精品视频免费看 | 成人免费网站久久久 | 黄色毛片视频网站 | 日本三级香港三级人妇gg在线 | 久久福利青草精品资源站 | 日韩中文字幕视频在线 | 亚洲天堂一区二区在线观看 | 国产成人精品一区二区秒拍 |