网站地图
  • 网站首页
  • 模板下载
  • 建站心得
  • 站长百科
  • 素材风暴
  • 源码时代
  • 源码入门
  • PHP与服务器端通讯方法

    发布时间: 2021-06-20 21:02首页:蜡笔源码 > 源码入门 > php学习 > 阅读()
    假设有10个网站,分布在各地,它们的库存要同步,而数据库不支持远程连接。大家要实时地获得服务器的库存数,可以通过非常多种办法,我所知晓的有以下几种:<?h3hh3require_once ’class/Htth3Client.h3hh3’;$h3arams = array;$h3ageContents = Htth3Client::quickPost;$result = exh3lode;h3rint_r;?>

    PHP5中的SOAP方法

    server.php

    <?php function getQuote { global $dbh;$result = array;try {$query = "SELECT fprice, fcansale, fbalance,
     fbaltip FROM tblbalance where upper) 
    = :psep limit 1";$stmt = $dbh->prepare;$stmt->execute)));$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;while) {//}} catch  {echo $e->getMessage;}return $fprice; //你可以返回一个数组} 
    $dsn = ’pgsql:host=192.168.*.* 
    port=5432 dbname=db user=123456 password=123456’;try {$dbh = new PDO;} catch  {die); }ini_set; // disabling WSDL cache $server = new SoapServer; //配置文件$server->addFunction; $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=’enpd’ namespace=’urn:xmethods-delayed-quotes’
    encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/>
    </input>
    <output>
    <soap:body use=’enpd’ 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

    ·CURL方法
    ·SOCKET方法
    ·PHP5中的SOAP方法

    以下分别给出示例来达成它:

    echo "OK," . $fh3seh3 . "," . $fbalance ;//以逗号分隔

    SOCKET方法

    这个要借用第三方类库HttpClient,可以到这里下载:http://scripts.incutio.com/httpclient/

    CURL方法

    client.php

    <?php$psep = ’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=" . $psep . "&amt=" . $amt;curl_seTOPt;curl_seTOPt;curl_seTOPt;//不直接输出,返回到变量$curl_result = curl_exec;$result = explode;curl_close;print_r;?> 

    服务器端仅需按肯定的格式输出,然后推广客户端按此格式接收就好了如:

    <?php$psep = ’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=" . $psep . "&amt=" . $amt;curl_seTOPt;curl_seTOPt;curl_seTOPt;//不直接输出,返回到变量$curl_result = curl_exec;$result = explode;curl_close;print_r;?> 

    服务器端仅需按肯定的格式输出,然后推广客户端按此格式接收就好了如:

    echo "OK," . $fpsep . "," . $fbalance ;//以逗号分隔

    SOCKET方法

    这个要借用第三方类库HttpClient,可以到这里下载:http://scripts.incutio.com/httpclient/

    <?phprequire_once ’class/HttpClient.php’;$params = array;$pageContents = HttpClient::quickPost;$result = explode;print_r;?>

    PHP5中的SOAP方法

    server.php

    <?php function getQuote { global $dbh;$result = array;try {$query = "SELECT fprice, fcansale, fbalance,
     fbaltip FROM tblbalance where upper) 
    = :psep limit 1";$stmt = $dbh->prepare;$stmt->execute)));$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;while) {//}} catch  {echo $e->getMessage;}return $fprice; //你可以返回一个数组} 
    $dsn = ’pgsql:host=192.168.*.* 
    port=5432 dbname=db user=123456 password=123456’;try {$dbh = new PDO;} catch  {die); }ini_set; // disabling WSDL cache $server = new SoapServer; //配置文件$server->addFunction; $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=’enpd’ namespace=’urn:xmethods-delayed-quotes’
    encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/>
    </input>
    <output>
    <soap:body use=’enpd’ 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; $result = $client->getQuote; print_r;?>
    特别声明:文章内容仅供参考,不造成任何投资建议。投资者据此操作,风险自担。

    网站首页 - 模板下载 - 建站心得 - 站长百科 - 素材风暴 - 源码时代 - 源码入门

    未经本站书面特别授权,请勿转载或建立镜像

    Copyright © 2002-2021 蜡笔源码 (http://www.028djc.com) 网站地图 TAG标签