PHP C++ 混合编程 paozhu 框架 1.5.6 发布,自带 URL 拦截


大量历史遗留PHP代码,公司要数据大屏,数据分析PHP难以胜任,现在paozhu框架可以满足你的需求。paozhu C++框架自带httpserver 支持http1 http2 通过拦截URL,达到PHP C++混合编程。

paozhu可以做PHP 前端,代替apache nginx,通过url拦截,区分走c++还是php.

paozhu 1.5.6 大量更新了ORM 代码

1 添加对,FrameworkBenchmarks 框架评测支持,下一轮可以看到paozhu排名。

    paozhu 经历上百万压力测试,各种压力测试都可以稳定应付,没有崩溃退出,没有内存飙升。

2 ORM添加 fetch_one和soft_remove 和几个where条件,官方教程马上会推出来。

    fetch_one 只取一条数据

    soft_remove 软删除,并非真正删除,而是标记数据表deleted 字段

3 修改了责任链方法,将来流程管理可以使用上。

经典FrameworkBenchmarks代码,paozhu可以轻松对应

#include "orm.h"
#include <chrono>
#include <thread>
#include "httppeer.h"
#include "techempower.h"
#include "techempower_json.h"
#include "datetime.h"
#include "func.h"
#include "pzcache.h"
#include "json_reflect_headers.h"
namespace http
{
//@urlpath(null,plaintext)
std::string techempowerplaintext(std::shared_ptr<httppeer> peer)
{
peer->type("text/plain; charset=UTF-8");
peer->set_header("Date", get_gmttime());
peer->output = "Hello, World!";
return "";
}

//@urlpath(null,json)
std::string techempowerjson(std::shared_ptr<httppeer> peer)
{
peer->type("application/json; charset=UTF-8");
peer->set_header("Date", get_gmttime());
struct techempower_outjson_t a;
a.message= "Hello, World!";
peer->output = json_encode(a);
return "";
}

//@urlpath(null,db)
std::string techempowerdb(std::shared_ptr<httppeer> peer)
{
peer->type("application/json; charset=UTF-8");
peer->set_header("Date", get_gmttime());
auto myworld= orm::World();
unsigned int rd_num = rand_range(1, 10000);
myworld.get_one(rd_num);

peer->output = myworld.data_tojson();
return "";
}

//@urlpath(null,queries)
std::string techempowerqueries(std::shared_ptr<httppeer> peer)
{
peer->type("application/json; charset=UTF-8");
peer->set_header("Date", get_gmttime());

unsigned int get_num = peer->get["queries"].to_int();
if (get_num == 0)
{
get_num = 1;
}
else if (get_num > 500)
{
get_num = 500;
}
auto myworld = orm::World();
for (unsigned int i = 0; i < get_num; i++)
{
myworld.wheresql.clear();
unsigned int rd_num = rand_range(1, 10000);
myworld.where("id", rd_num).fetch_append();
}

peer->output = myworld.to_json();
return "";
}

//@urlpath(null,fortunes)
std::string techempowerfortunes(std::shared_ptr<httppeer> peer)
{
peer->type("text/html; charset=UTF-8");
peer->set_header("Date", get_gmttime());

auto myfortune = orm::Fortune();
myfortune.fetch();
myfortune.data.id= 0;
myfortune.data.message = "Additional fortune added at request time.";
myfortune.record.push_back(myfortune.data);

std::sort(myfortune.record.begin(), myfortune.record.end(), [](const auto &lhs, const auto &rhs)
{ return lhs.message < rhs.message; });
peer->val["list"].set_array();
OBJ_ARRAY item;
for (unsigned int i = 0; i < myfortune.record.size(); i++)
{
item["id"]= myfortune.record[i].id;
item["message"] = html_encode(myfortune.record[i].message);
peer->val["list"].push(item);
}

peer->view("techempower/fortunes");
return "";
}

//@urlpath(null,updates)
std::string techempowerupdates(std::shared_ptr<httppeer> peer)
{
peer->type("application/json; charset=UTF-8");
peer->set_header("Date", get_gmttime());
unsigned int get_num = peer->get["queries"].to_int();

if (get_num == 0)
{
get_num = 1;
}
else if (get_num > 500)
{
get_num = 500;
}
auto myworld = orm::World();
myworld.record.clear();
for (unsigned int i = 0; i < get_num; i++)
{
myworld.wheresql.clear();
unsigned int tempid = rand_range(1, 10000);
myworld.where("id", tempid).fetch_append();
if (myworld.effect() > 0)
{
unsigned int j = myworld.record.size() - 1;
myworld.data.randomnumber= rand_range(1, 10000);
myworld.record[j].randomnumber = myworld.data.randomnumber;
myworld.update("randomnumber");
}
}
peer->output = myworld.to_json();
return "";
}

//@urlpath(null,cached-queries)
std::string techempowercached_queries(std::shared_ptr<httppeer> peer)
{
peer->type("application/json; charset=UTF-8");
peer->set_header("Date", get_gmttime());

unsigned int get_num = peer->get["count"].to_int();
if (get_num == 0)
{
get_num = 1;
}
else if (get_num > 500)
{
get_num = 500;
}
auto myworld= orm::World();
std::string mycacheid = "alldatacache";

pzcache<std::vector<orm::worldbase::meta>> &temp_cache = pzcache<std::vector<orm::worldbase::meta>>::conn();

std::vector<orm::worldbase::meta> allcachedata_array;
//create rand data to cache
if (temp_cache.check(mycacheid) > -1)
{
allcachedata_array = temp_cache.get(mycacheid);
}
else
{
allcachedata_array.resize(10000);
for (unsigned int i = 0; i < 10000; i++)
{
allcachedata_array[i].id = i + 1;
allcachedata_array[i].randomnumber = rand_range(1, 10000);
}
temp_cache.save(mycacheid, allcachedata_array, 120);
}
//get rand data from cache
mycacheid = "my" + std::to_string(get_num);
if (temp_cache.check(mycacheid) > -1)
{
myworld.record = temp_cache.get(mycacheid);
}
else
{
if (allcachedata_array.size() == 10000)
{
for (unsigned int i = 0; i < get_num; i++)
{
unsigned int temp_rid = rand_range(0, 9999);
myworld.record.push_back(allcachedata_array[temp_rid]);
}
}
temp_cache.save(mycacheid, myworld.record, 120);
}

peer->output = myworld.to_json();
return "";
}

//@urlpath(null,cached-db)
std::string techempowercached_db(std::shared_ptr<httppeer> peer)
{
peer->type("application/json; charset=UTF-8");
peer->set_header("Date", get_gmttime());
//this test from database to cache
unsigned int get_num = peer->get["count"].to_int();
if (get_num == 0)
{
get_num = 1;
}
else if (get_num > 500)
{
get_num = 500;
}
auto myworld= orm::World();
std::string mycacheid = "my" + std::to_string(get_num);

pzcache<std::vector<orm::worldbase::meta>> &temp_cache = pzcache<std::vector<orm::worldbase::meta>>::conn();

if (temp_cache.check(mycacheid) > -1)
{
myworld.record = temp_cache.get(mycacheid);
}
else
{
std::vector<unsigned int> cacheid;
for (unsigned int i = 0; i < get_num; i++)
{
cacheid.push_back(rand_range(1, 10000));
}

std::string sqlstr = array_to_sql(cacheid);
myworld.whereIn("id", sqlstr).fetch();
temp_cache.save(mycacheid, myworld.record, 120);
}

peer->output = myworld.to_json();
return "";
}

}// namespace http

https://github.com/hggq/paozhu


相關推薦

2023-12-03

。 上一版已经添加了支持PHP FAST-CGI,模式,支持PHP和c++混合编程, 比如一个地址是旧的php代码,另一个地址是C++代码 news/list 访问是旧的php框架代码 news/show 访问是c++新的功能。 paozhu C++ Web框架 内置ORM JSON解析 1.特性🔥🔥

2023-12-21

库 ✅15. 生成二维码(qrcode),需要gd、qrencode库 ✅16. 插件化编程,热动态更新,使用动态库方式 ✅17. 框架内置通用数据缓存模块,ORM结果缓存,提高并发能力 ✅18. 框架controller目录注解功能,方便添加URL路由映射,降低入门心智

2022-12-25

mail ✅15. 生成二维码(qrcode),需要gd、qrencode库 ✅16. 插件化编程,热动态更新,使用动态库方式 https://github.com/hggq/paozhu  

2023-06-04

库 ✅15. 生成二维码(qrcode),需要gd、qrencode库 ✅16. 插件化编程,热动态更新,使用动态库方式 ✅17. 框架内置通用数据缓存模块,ORM结果缓存,提高并发能力 ✅18. 框架controller目录注解功能,方便添加URL路由映射,降低入门心智

2023-06-25

库 ✅15. 生成二维码(qrcode),需要gd、qrencode库 ✅16. 插件化编程,热动态更新,使用动态库方式 ✅17. 框架内置通用数据缓存模块,ORM结果缓存,提高并发能力 ✅18. 框架controller目录注解功能,方便添加URL路由映射,降低入门心智

2023-10-07

Paozhu(炮竹🧨)是一个全面、快速的C++ web framework 开发框架,集成C++ ORM,开发速度跟脚本语言一样,日写1000行业务代码没有压力,框架集成了WebServer,自己原生解析HTTP/1、HTTP/2、JSON协议 Paozhu C++ Web Framework 1.4.6发布 新功能 添加

2023-04-25

经过实际项目开发,根据反馈和修复, 已经发布1.3.0版 paozhu框架 集成ORM HTTP/2 功能,压力测试可以平稳运行。 https://github.com/hggq/paozhu 1.3.0版更新内容 新版添加了 结构体或类对象 json_encode json_decode 功能 支持结构体嵌套和组

2023-07-20

通过分析超 1400 万个开发人员职位,并从中筛选了有明确编程语言需求的职位,得出了在 2023 年需求量最大的 8 种 语言。 目前市场中需求最高的前八位语言分别是: 1、JavaScript / TypeScript 和以往一样,Javascript 仍然保持流行

2022-12-14

过 1200 万个开发人员职位需求,并从其中挑选了明确需要编程语言的工作机会,得到了 2022 年最受欢迎的 8 种编程语言。 目前市场中需求最高的前八位语言分别是: 1、JavaScript / TypeScript 自创建以来,JavaScript 就一直保持着

2022-07-01

万份开发者工作需求,得出了目前行业需求量最高的 8 种编程语言。 需要注意的是,在这 700 万份工作需求中,DevJobsScanner 只挑选了有明确编程语言要求的工作,舍弃了对语言要求比较模糊的工作。 让我们一起看看在目前的市

2022-04-02

析公司 RedMonk 发布了 2022 年 1 月(第一季度)。 RedMonk 编程语言排行榜通过追踪编程语言在 GitHub 和 Stack Overflow 上的代码使用情况与讨论数量,统计分析后进行排序,其旨在深入了解潜在的语言采用趋势。该榜单一年发布两次

2023-04-03

文档以及配置。 该版本附带了一些 bug fixe、10 多种编程语言的功能增强(#Kotlin #Python #csharp #java #erlang #rustlang 等)以及 OpenAPI Normalizer 中的几条新 rules。 有一个带有 fallback 的破坏性变更:[Java][Spring] 选项是否生成所需

2023-04-14

gRPC 是可以在任何环境中运行的现代开源高性能 RPC 框架。gRPC 1.54.0 现已发布,包含了一些完善、改进和错误修复;具体更新内容如下: Core 根据 Foundational C++ 支持,gRPC 放弃了对 Visual Studio 2017 的支持,gRPC 支持的最低 Vis

2022-11-14

软件行业分析公司 RedMonk 发布了 2022 年 6 月(第三季度)编程语言排行榜。 RedMonk 编程语言排行榜通过追踪编程语言在 GitHub 和 Stack Overflow 上的代码使用情况与讨论数量,统计分析后进行排序,其旨在深入了解潜在的语言采用