欢迎光临
我们一直在努力

PHP程序与服务器端通讯方法小结 (2)-PHP教程,PHP应用

建站超值云服务器,限时71元/月

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);
?>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » PHP程序与服务器端通讯方法小结 (2)-PHP教程,PHP应用
分享到: 更多 (0)