六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

PHP程序與服務器端通訊方法小結

[摘要]假設有10個網站,分布在各地,它們的庫存要同步,而數據庫不支持遠程連接。   我們要實時地取得服務器的庫存數,可以通過很多種方法,我所知道的有以下幾種:    ·CURL方式    ·SOCKET方式    ·PHP5中的SOAP方式   以下分別給出示例來實現它: ...
假設有10個網站,分布在各地,它們的庫存要同步,而數據庫不支持遠程連接。

  我們要實時地取得服務器的庫存數,可以通過很多種方法,我所知道的有以下幾種:

   ·CURL方式

   ·SOCKET方式

   ·PHP5中的SOAP方式

  以下分別給出示例來實現它:

  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);
?>
  服務器端只需按一定的格式輸出,然后客戶端按此格式接收就可以了如:

echo "OK," . $fpsecode . "," . $fbalance ;//以逗號分隔
  SOCKET方式

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

<?php
require_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; //你可以返回一個數組


$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’> 
<operation name=’getQuote’> 
<input message=’tns:getQuoteRequest’/> 
<output message=’tns:getQuoteResponse’/> 
</operation> 
</portType> 

<binding name=’StockQuoteBinding’ type=’tns:StockQuotePortType’> 
<soap:binding style=’rpc’ 
transport=’http://schemas.xmlsoap.org/soap/http’/> 
<operation 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> 
<output> 
<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);
?>



主站蜘蛛池模板: 四虎永久在线精品免费影视 | 青草青视频在线观看 | 四虎永久免费影院在线 | 亚洲精品中文字幕区 | 亚洲一区二区在线播放 | 四虎在线最新永久免费 | 四虎影院观看视频 | 午夜欧美性视频在线播放 | 日本视频一区二区 | 欧美婷婷| 亚洲图欧美| 午夜影院免费在线观看 | 伊人手机在线视频 | 日本激情视频 | 天天干天天爽天天射 | 青免费视频 | 性做久久久久 | 午夜国产精品影院在线观看 | 四虎影院永久免费 | 亚洲高清视频在线 | 午夜在线播放视频在线观看视频 | 性天堂网| 天天躁夜夜躁狠狠躁 | 青青青国产手机在线播放 | 制服丝袜自拍偷拍 | 在线视频一区二区日韩国产 | 亚洲产国偷v产偷v自拍色戒 | 亚洲最大的成人网 | 午夜爱爱免费视频 | 亚洲欧美无人区乱码 | 婷婷狠狠干 | 午夜精| 泰剧不期而爱第三季免费全集观看 | 亚洲第一精品夜夜躁人人爽 | 中文字幕色综合久久 | 日本免费色网站 | 亚洲国产欧美在线人成app | 一区二区三区视频免费观看 | 特黄特色的大片观看免费视频 | 午夜黄色福利视频 | 鸥美一级黄色片 |