您现在的位置是:首页 > 文章详情

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

日期:2024-01-15点击:245

大量历史遗留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

原文链接:https://www.oschina.net/news/275782/paozhu-1-5-6-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章