欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

SOA面向服務框架設計與實現(xiàn)

文章節(jié)選自 《Netkiller Architect 手札》

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網(wǎng)站設計制作、成都網(wǎng)站設計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的吉木薩爾網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!

由于Java 語言的編譯與重啟不可抗拒缺陷,所選擇使用PHP彌補這個缺陷。

在合適的場景中使用PHP 為 Java 提供 SOA 服務有很多優(yōu)勢,的優(yōu)勢就是升級,能夠隨時升級,即時生效,服務不中斷。

任何一種語言都有其擅長的一面,多種語言互補是一種趨勢。

14.4.Service-oriented architecture (SOA)

SOA 與 REST很多相同之處,目前SOA主要是基于SOAP實現(xiàn),也有基于MQ的實現(xiàn)。而REST只限于HTTP POST/GET/PUT/DELETE等等。

我個人比較喜歡機遇TCP的SOA實現(xiàn),不喜歡SOAP大量XML傳輸。

14.4.1.SOAP實現(xiàn)

這里提供一個簡單的機遇SOAP實現(xiàn)的SOA框架

index.php入口文件

<?php define (\'CONFIG_DIR\', \'../config/\'); define (\'LIBRARY_DIR\', \'../library/\'); define (\'DEBUG\', false); //define (\'DEBUG\', ture); require_once(CONFIG_DIR. \'default.php\'); $remote_addr = $_SERVER[\'REMOTE_ADDR\']; if(!in_array($remote_addr, $firewall)) { printf("Permission denied: %s", $remote_addr); exit(0); } $request_uri = $_SERVER[\'REQUEST_URI\']; $classspath = LIBRARY_DIR.strtolower($request_uri) . \'.class.php\'; if( is_file($classspath) ){ require_once($classspath); }else{ die("Cannot loading interface!"); } $class = ucfirst(substr($request_uri, strrpos($request_uri, \'/\')+1)); if( DEBUG ){ printf("%s<br>",$class); } if (class_exists($class)) { $server = new SoapServer(null, array(\'uri\' => "http://webservice.example.com")); $server->setClass($class); $server->handle(); }else{ die(\'Object isnot exist.\'); }

接口文件

<?php require_once(\'common.class.php\'); class Members extends Common{ private $dbh = null; public function __construct() { parent::__construct(); $this->dbh = new Database(\'slave\'); } public function getAllByUsernameAndMobile($username,$mobile){ $result = array(); if(empty($username) or empty($mobile)){ return($result); } $sql = "SELECT username, chinese_name, sex FROM members m, members_digest md WHERE m.id = md.id and m.username= :username and md.mobile = md5( :mobile );"; $stmt = $this->dbh->prepare($sql); $stmt->bindValue(\':username\', $username); $stmt->bindValue(\':mobile\', $mobile); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return($result); } public function getAllByLimit($limit,$offset) { $sql = "SELECT username FROM members limit ".$limit.",".$offset; $stmt = $this->dbh->query($sql); while ($row = $stmt->fetch()) { //printf("%srn", $row[\'username\']); $result[] = $row[\'username\']; } return $result; } function __destruct() { $this->dbh = null; } }

客戶端調用實例

<?php $options = array(\'uri\' => "http://webservice.example.com", \'location\'=>\'http://webservice.example.com/members\', \'compression\' => \'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP\', \'login\'=>\'neo\', \'password\'=>\'chen\', \'trace\'=>true ); $client = new SoapClient(null, $options); try { print_r($client->getAllByUsernameAndMobile(\'280600086\',\'13113668890\')); print_r($client->getAllByLimit(20,20)); } catch (Exception $e) { echo \'Caught exception: \', $e->getMessage(), "n"; }

Nginx 虛擬主機配置文件 /etc/nginx/conf.d/webservice.example.com.conf

server { listen 80; server_name webservice.example.com; charset utf-8; access_log /var/log/nginx/webservice.example.com.access.log main; auth_basic "Login"; auth_basic_user_file htpasswd; location / { root /www/example.com/webservice.example.com/htdocs; index index.html index.php; if ($request_filename !~ (js|css|images|robots/.txt|.*.html|index/.php) ) { rewrite ^/(.*)$ /index.php/$1 last; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ /index.php/ { root /www/example.com/webservice.example.com/htdocs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /www/example.com/webservice.example.com/htdocs$fastcgi_script_name; include fastcgi_params; } }

每增加一個功能需求,在library中創(chuàng)建一個 Class 文件即可。

index.php 有IP過濾功能,禁止非法IP訪問

客戶端采用壓縮傳輸,節(jié)省xml傳輸開銷

Nginx 設置了HTTP認證,防止他人探測,另外提示你還可以采用雙向SSL認證。

有興趣可以看看這個項目:

https://github.com/netkiller/SOA

延伸閱讀

數(shù)據(jù)庫安全·保護表

數(shù)據(jù)庫安全·保護表字段

數(shù)據(jù)庫安全·時間一致性

數(shù)據(jù)庫安全·為數(shù)據(jù)安全而分庫

數(shù)據(jù)庫安全·內容版本控制,撰改留痕

數(shù)據(jù)庫安全·用戶/角色認證

數(shù)據(jù)庫安全·Token 認證

數(shù)據(jù)庫安全·數(shù)據(jù)加密

數(shù)據(jù)庫安全·開發(fā)加密插件

數(shù)據(jù)與應用程序間通信·UDP Socket

關注作者公眾號,每日推送原創(chuàng)文章。如果已有什么建議,請給我留言。

分享文章:SOA面向服務框架設計與實現(xiàn)
URL標題:http://www.chinadenli.net/article20/cgieco.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供建站公司網(wǎng)站策劃云服務器營銷型網(wǎng)站建設標簽優(yōu)化品牌網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司