soyizi 发表于 2017-5-1 13:01:00

phprpc for Python 和flup的配置

  phprpc是非常好用的一个远程调用方案.以前曾经在dotnet中简单使用过.最近看了看python,发现phprpc也支持!
  准备用在生产环境中.先测试下.把过程记录下来.
  1.下载安装python2.52,高效稳定的版本.
  2.下载安装phprpc:http://www.phprpc.org/zh_CN/download
  3.下载安装flup,我先使用了flup在python主页上的版本,竟然没有flup.middleware.session,flup.middleware.gzip.
  而flup的老家竟然不能访问! google,发现了svn!
  直接用 svn co http://svn.saddi.com/flup/  下载到本地,然后setup.py install
  4.就用官方网站代码测试:
  服务器端:

from flup.middleware.session import MemorySessionStore, SessionMiddleware   
from flup.middleware.gzip import GzipMiddleware   
from phprpc import PHPRPC_WSGIApplication, UrlMapMiddleware, PHPRPC_Server   
import datetime   
def helloworld():   
return 'helloworld'
def hi(name):   
return 'hi %s' % name   
app = PHPRPC_WSGIApplication()   
app.add(helloworld)   
app.add('hi')   
app.add(hi, 'hello')   
app.add(datetime.datetime.now)   
app.debug = True
app = UrlMapMiddleware([('/', app)])   
sessionStore = MemorySessionStore()   
app = SessionMiddleware(sessionStore, app)   
app = GzipMiddleware(app)   
PHPRPC_Server(app = app).start()
  客户端:

#coding=cp936
from phprpc import PHPRPC_Client
import phpformat
#import datetime
client = PHPRPC_Client('http://127.0.0.1:80/')
client.keylength = 256 # 加密长度   
client.encryptmode = 2 # 双向加密
print client.helloworld()
print client.hi("ideage")
  输出:
  D:\MyApps\phprpc>phrcc.py
helloworld
hi ideage
  测试成功!感谢大家........
  期待Eurasia支持wsgi.....
页: [1]
查看完整版本: phprpc for Python 和flup的配置