【任务6】tf和cgi进行联合试验,完成日志服务器

改装gen-cpp目录下client.cpp文件

  • 代码如下:
#include "RecSys.h"
#include <iostream>
#include <string> #include <transport/TSocket.h>
#include <transport/TBufferTransports.h>
#include <protocol/TBinaryProtocol.h> #include <fcgi_stdio.h>
#include <fcgiapp.h> using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport; using namespace std;
using std::string;
using boost::shared_ptr; inline void send_response(
FCGX_Request& request, const std::string& resp_str) { FCGX_FPrintF(request.out, "Content-type: text/html;charset=utf-8\r\n\r\n");
FCGX_FPrintF(request.out, "%s", resp_str.c_str());
FCGX_Finish_r(&request);
} int main(int argc, char **argv){
// 1.初始化cgi
FCGX_Init();
FCGX_Request request;
FCGX_InitRequest(&request, 0, 0); // 2.连接connect server rpc
boost::shared_ptr<TSocket> socket(new TSocket("localhost",9090));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); transport->open(); RecSysClient client(protocol); while(FCGX_Accept_r(&request) >= 0) { // http page -> client
std::string send_data = FCGX_GetParam("QUERY_STRING", request.envp); string receive_data; // client >> server
// server >> client
client.rec_data(receive_data,send_data); cout << "receive http params: " << send_data << std::endl;
cout << "receive server data: " << receive_data << endl; /*send_response(request, return_str);*/
send_response(request, receive_data);
} transport->close();
return 0;
}

启动Nginx服务和gen-cpp目录下编译后的"server"

  • client.cpp文件代码修改为:
#include "RecSys.h"
#include <iostream>
#include <string> #include <transport/TSocket.h>
#include <transport/TBufferTransports.h>
#include <protocol/TBinaryProtocol.h> #include <fcgi_stdio.h>
#include <fcgiapp.h> using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport; using namespace std;
using std::string;
using boost::shared_ptr; inline void send_response(
FCGX_Request& request, const std::string& resp_str) { FCGX_FPrintF(request.out, "Content-type: text/html;charset=utf-8\r\n\r\n");
FCGX_FPrintF(request.out, "%s", resp_str.c_str());
FCGX_Finish_r(&request);
} int main(int argc, char **argv){
// 1.初始化cgi
FCGX_Init();
FCGX_Request request;
FCGX_InitRequest(&request, 0, 0); // 2.连接connect server rpc
boost::shared_ptr<TSocket> socket(new TSocket("localhost",9090));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); transport->open(); RecSysClient client(protocol); while(FCGX_Accept_r(&request) >= 0) { // http page -> client
std::string send_data = FCGX_GetParam("QUERY_STRING", request.envp); string receive_data; // client >> server
// server >> client
client.rec_data(receive_data,send_data); cout << "receive http params: " << send_data << std::endl;
cout << "receive server data: " << receive_data << endl; /*send_response(request, return_str);*/
send_response(request, receive_data);
} transport->close();
return 0;
}

Makefile 文件修改为

G++ = g++
CFLAGS = -g -Wall
INCLUDES = -I./ -I/usr/local/include/thrift
LIBS = -L/usr/local/lib/*.so -lthrift SER_OBJECT = RecSys.cpp RecSys_constants.cpp RecSys_types.cpp RecSys_server.skeleton.cpp
CLI_OBJECT = RecSys.cpp client.cpp server: $(SER_OBJECT)
$(G++) $(CFLAGS) $(INCLUDES) $(SER_OBJECT) $(LIBS) -o server client: $(CLI_OBJECT)
$(G++) $(CFLAGS) $(INCLUDES) $(CLI_OBJECT) $(LIBS) -o client .PHONY: clean
clean:
rm -f server client
  • 命令:make servermake clientmake clean等会对应执行名相应的命令

启动Nginx服务

  • 命令:安装目录/sbin/nginx
  • 检查端口是否开启:netstat -antup | grep nginx,端口为:80
  • 打开浏览器查看服务是否开启,查看

启动gen-cpp目录下的"server"

  • 命令:./server
  • 此时已经启动了cgi代理,查看端口是否监听成功:netstat -antup | grep 8088

启动cgi服务

  • 启动之前先编译client.cpp文件,命令:make client

  • 命令:/usr/local/src/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 8088 -f /test/thrift_test/python_thrift_demo/gen-cpp/client

查看整个流程的服务是否成功

  • 打开浏览器,查看,页面(也就是客户端)会返回server端输出的内容,同时server端会接收到客户端(也就是浏览器)发送的信息

  • 如图:

  • 带参数:

    • 客户端:

    • server端:

【六】tf和cgi进行联合试验,完成日志服务器的更多相关文章

  1. MySQL (六)--外键、联合查询、子查询

    1 外键 外键:foreign key,外面的键(键不在自己表中),如果一张表中有一个字段(非主键)指向另外一张表的主键,那么将该字段称为外键. 1.1 增加外键 外键可以在创建表的时候或创建表之后增 ...

  2. SQL语句(六)分页查询和联合查询

    目录 一.分页查询 语法格式 应用 二.联合查询 语法和作用 特点 应用 UNION和UNION ALL的区别 一.分页查询 语法格式 SELECT 查询列表 FROM 表 WHERE ... GRO ...

  3. Python的CGI编程实现-通过接口运行服务器py脚本

    yum 安装apcche [apache]yum 安装Apache(Centos 6.9) https://www.cnblogs.com/lauren1003/p/5993654.html只需一行命 ...

  4. 指定的 CGI 应用程序遇到错误,服务器终止了该进程。

    遇到这种错误只需要把这个项目的Cookies删除再重新启动就行了

  5. springboot学习入门简易版六---springboot2.0整合全局捕获异常及log4j日志(12-13)

    使用Aop实现 1创建异常请求 在原有项目基础上,jspController中创建一个可能发生异常的请求: /** * 全局捕获异常测试 * @param i * @return */ @Reques ...

  6. #企业项目实战 .Net Core + Vue/Angular 分库分表日志系统六 | 最终篇-通过AOP自动连接数据库-完成日志业务

    教程预览 01 | 前言 02 | 简单的分库分表设计 03 | 控制反转搭配简单业务 04 | 强化设计方案 05 | 完善业务自动创建数据库 06 | 最终篇-通过AOP自动连接数据库-完成日志业 ...

  7. Azure DevOps (六) 通过FTP上传流水线制品到Linux服务器

    上一篇我们实现了把流水线的制品保存到azure的流水线制品仓库里去,本篇我们会开始研究azure的发布流水线. 本篇要研究的是把流水线仓库的制品发布到任意一台公网的linux服务器上去,所以我们先研究 ...

  8. 第六章:Django 综合篇 - 14:Django 日志

    Django使用Python内置的logging模块实现它自己的日志系统. 如果你没有使用过logging模块,请参考Python教程中的相关章节. 直达链接<logging模块详解>. ...

  9. 【转】初识CGI

    一.基本原理 CGI:通用网关接口(Common Gateway Interface)是一个Web服务器主机提供信息服务的标准接口.通过CGI接口,Web服务器就能够获取客户端提交的信息,转交给服务器 ...

随机推荐

  1. 轻松应对IDC机房带宽突然暴涨问题

    轻松应对IDC机房带宽突然暴涨问题! 1[提出问题] [实际案例一] 凌晨3:00点某公司(网站业务)的一个IDC机房带宽流量突然从平时高峰期150M猛增至1000M,如下图: 该故障的影响:直接导致 ...

  2. c#(winform)环境下使用动态链接库dll的详解

    1,什么是dll文件? DLL(Dynamic Link Library)文件为动态链接库文件,又称“应用程序拓展”,是软件文件类型.在Windows中,许多应用程序并不是一个完整的可执行文件,它们被 ...

  3. Exchange Server 2016 安卓手机打不开超过10M的附件问题处理

    华为手机配置Exchange Server 2016  时,打不开超过10M的附件,如PPT或者是DOC之类的附件,而iphone手机确可以,因为iphone手机使用了IMAP协议,安卓手机如果使用I ...

  4. rsync- sersync -inotify

    Rsync简介 Rsync是一款优秀的.快速的.多功能的本地或远程数据镜像同步备份工具.适用于unix/linux/windows等多种平台 从软件的名称Rsync(Remote Rynhroniza ...

  5. pandas 入门

    1. 默认的pandas不能读取excel.需要安装xlrd, xlwt才能支持excel的读写 pip install xlrd #添加读取excel功能 pip install xlwt #添加写 ...

  6. JavaScript的DOM_操作行内样式

    一.检测浏览器是否支持css CSS 作为(X)HTML 的辅助,可以增强页面的显示效果.但不是每个浏览器都能支持最新的 CSS 能力.CSS 的能力和 DOM 级别密切相关,所以我们有必要检测当前浏 ...

  7. Spring+ehcache+redis两级缓存

    问题描述 场景:我们的应用系统是分布式集群的,可横向扩展的.应用中某个接口操作满足以下一个或多个条件: 1. 接口运行复杂代价大, 2. 接口返回数据量大, 3. 接口的数据基本不会更改, 4. 接口 ...

  8. A blog about Core Animation and other iOS graphics framework

    A blog about Core Animation and other iOS graphics frameworks. https://www.calayer.com/

  9. 安装LAMP PHP的./configure 參数,未出现MYSQ

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/default7/article/details/30613781 编译參数: ./configure ...

  10. mysql 聚集和非聚集索引 解析

    一.聚集索引(聚簇索引) 1. 什么是聚集索引? 比如要查找'hello',则直接找内容为hello的行,我们把这种正文内容本身就是一种按照一定规则排列的目录称为“聚集索引”.   聚集索引的叶子节点 ...