1 通过thrift

但是数据量太大thrift不支持

下载thrift包安装,比如我的是/usr/local/thrift-0.8.0

/usr/local/thrift-0.8.0/lib类库

/usr/local/thrift-0.8.0/test是你需要的教程 可以通过教材方便使用thrift

通信thrift文件

helloworld .thrift

你要写什么格式可以参照  test里面

service HelloWorld{

string sayHello(1:string content, 2:string xpath)

}

thrift -gen python xxx.py

thrift -gen php xxx.py

python服务端 。

test.py

import sys

2 sys.path.append('/var/www/thrift/gen-py')

3 from helloworld import HelloWorld

4 from helloworld.ttypes import *

5 from thrift.transport import TSocket

6 from thrift.transport import TTransport

7 from thrift.protocol import TBinaryProtocol

8 from thrift.server import TServer

9 import socket

10 from lxml.html.soupparser import fromstring

11

12 class HelloWorldHandler:

13     def __init__(self):

14         self.log = {}

15

16     #def sayHello(self, content, xpath):

17         #content = """

why len(y) ==< 1sample."""

18     def sayHello(self, content, xpath):

19         root = fromstring(content)

20         find_text = root.xpath(xpath)

21         return find_text[0].text

22

23 handler = HelloWorldHandler()

24 processor = HelloWorld.Processor(handler)

25 transport = TSocket.TServerSocket('127.0.0.1', 393939)

26 tfactory = TTransport.TBufferedTransportFactory()

27 pfactory = TBinaryProtocol.TBinaryProtocolFactory()

28 server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

29 print 'start server'

30 server.serve()

test.php

<?PHP   2 $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__).'/Thrift';   3 require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';   4 require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';   5 require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';   6 require_once $GLOBALS['THRIFT_ROOT'].'/transport/THttpClient.php';   7 require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';   8    9 // Your gen-php dir  10 $GEN_DIR = dirname(__FILE__).'/gen-php';  11 require_once $GEN_DIR . '/helloworld/HelloWorld.php';  12 require_once $GEN_DIR . '/helloworld/helloworld_types.php';  13   14 // Set server host and port  15 $host = "127.0.0.1";  16 $port = 393939;  17   18 try {  19   20     //Thrift connection handling  21     $socket = new TSocket( $host , $port, true );  22     $transport = new TBufferedTransport($socket, 1024, 1024);  23     $protocol = new TBinaryProtocol($transport);  24     #echo "

";  25     #print_r($socket);  26     #print_r($transport);  27     #print_r($protocol);  28     // get our example client  29     $client = new HelloWorldClient($protocol);  30     $transport->open();  31   32     #$in = new ThriftTest_Page();  33     // Get current timestamp from server  34     $content = file_get_contents("http://www.baidu.com/");  35     $content = mb_convert_encoding($content, "UTF-8");  36 //  $content = "why len(y) ==< 1sample.";  37 //  die;  38     $xpath = "//title";  39     #$in->content = $content;  40     #$in->xpath = $xpath;  41   42     $return = $client->sayHello($content, $xpath);  43 //  $return = $client->sayHello($content, $xpath);  44     echo $return;  45   46     $transport->close(); } catch (TException $tx) {  49     print 'Something went wrong: '.$tx->getMessage()."\n";  50 }  51 ?>

python 和php的数据通信_python服务端 和 php客户端通信一相关推荐

  1. phpsocket服务端和VC客户端通信实例

    首先编辑php.ini, 打开extension=php_sockets.dll, 修改完成之后重启apache 可以加下如下代码判断是否开启php_sockets if(extension_load ...

  2. python学习随堂笔记—TCP服务端与客户端

    思想: 1. 客户端 向服务端 发起连接 2. 服务端 接到请求,双方建立连接 3. 客户端 向 服务端发消息 4. 服务端 应答客户端 5. 服务端 与客户端循环读写操作 6. 操作完成之后客户端发 ...

  3. ssm配置socket_ssm框架中集成websocket实现服务端主动向客户端发送消息

    找了很多配置文档及实例说明,也还是没能成功,最终在csdn博客中发现了基于stomp的消息推送的文章, 下面整理自csdn博客,https://blog.csdn.net/u013627689/art ...

  4. 服务端渲染vs客户端渲染到前后端同构

    关于服务端渲染与客户端渲染的优劣,互联网上已经有过很多的文章进行过分析,在这里我谈一下我个人的见解. 首先,还是来老生常谈一下关于两种渲染方式的主要优劣: 服务端渲染(仅列出当下最突出的优劣): 优: ...

  5. netty tcp服务端主动断开客户端_「Netty核心技术」6-ChannelPipeline源码

    ChannelPipeline是Channelhandler的容器,它负责ChannelHandler的管理和事件拦截与调度. 土话: ChannelPipeline就是用来管理Channelhand ...

  6. websocket服务端和html客户端进行二进制数据交互

    一.概念和理论理解 1.HTTP HTTP 是基于请求响应式的,即通信只能由客户端发起,服务端做出响应,无状态,无连接. 无状态:每次连接只处理一个请求,请求结束后断开连接. 无连接:对于事务处理没有 ...

  7. 内网穿透-利用frp进行远程桌面控制(window服务端,window客户端)

    内网穿透-利用frp进行远程桌面控制(window服务端,window客户端) 参考链接 https://blog.csdn.net/weixin_38416696/article/details/1 ...

  8. 【踩坑】cat3.x服务端部署, springboot客户端接入

    [踩坑]cat3.x服务端部署, springboot客户端接入 前言 服务器部署问题 1. 数据库连不上 2. 不要创建server.xml 客户端注册问题 1. client.xml信息错误 2. ...

  9. android java websocket client_websocket服务端,android客户端示例

    服务端库依赖详见章末 #####spring websocket服务端代码(会话过程) public class HandshakeInterceptor extends HttpSessionHan ...

最新文章

  1. pyqt5教程11:绘制外观
  2. IDEA中安装MyBatis Log Plugin插件完整显示执行的mybatis的sql语句
  3. Firebug 1.7正式版发布,支持Firefox 4
  4. IntelliJ IDEA 如何创建一个普通的java项目,及创建java文件并运行
  5. C#中要使一个类支持FOREACH遍历,实现过程怎样? [转]
  6. Uno 平台 一 WinUI终极跨平台方案(二)
  7. Nagios Plugin for Cacti (npc插件) Download 下载
  8. 通用业务平台设计(一):概览
  9. Mysql 两种情况下更新字段中部分数据的方法
  10. React Native初探
  11. linux NFS共享
  12. mescroll下拉刷新上拉加载
  13. html5好看的注册页面设计,美观大气注册登录页面模板html源码
  14. 小鸟云服务器如何进行重装系统?
  15. 用c语言实现基本数据结构(哈希表)
  16. 【PMP】关键路径法与关键链法
  17. html代码中title什么意思,html中title啥意思
  18. AKK菌——下一代有益菌
  19. 12.郝斌C语言笔记——枚举
  20. java毕业生设计茶店订购管理系统计算机源码+系统+mysql+调试部署+lw

热门文章

  1. int **a[3][4] 和 sizeof(a) 和 int(**)a[3][4]
  2. pear Auth的使用
  3. 5.MySQL Cluster(MySQL集群)
  4. 凌轩:中国电信在校园市场的困与囧
  5. Halcon 摄像机标定流程
  6. QT之计算器代码重构(六)
  7. Reids实战(7)数据类型五sorted sets
  8. yii2 postman 文件上传
  9. 通过Java字节码发现有趣的内幕之String篇(上)(转)
  10. 防火墙DNAT与SNAT详谈