php - 如何在使用 Boost C++(在共享区域中)编写的 php Web 应用程序中读取 map ?

标签 php c++ boost

我在共享区域中使用 C++、Boost 库编写了一个映射(键、值)。

void CreateIndexMap()
{
    shared_memory_object::remove(Getsharedmemoryregion());
    managed_shared_memory segment(create_only,Getsharedmemoryregion(), 10000000);
    void_allocator alloc_inst (segment.get_segment_manager());
    complex_map_type *mymap = segment.construct<complex_map_type>("MyMap")(std::less<char_string>(), alloc_inst);             
}

在共享区域创建内存映射:

void UpdateIndexMap(std::string str, std::string index, const char* SharedMemory)
 {
    managed_shared_memory segment(open_only,SharedMemory);
    void_allocator alloc_inst (segment.get_segment_manager());
    complex_map_type *mymap = segment.find<complex_map_type>("MyMap").first;
    std::string h = ConvertTolowercase(str);
    char_string patternvalue(h.c_str(), alloc_inst);
    char_string indexvalue((index).c_str(), alloc_inst);  
    mymap->insert(std::pair<char_string, char_string>(patternvalue,indexvalue));
 }

现在我正在使用 PHP 开发一个 Web 应用程序,并希望读取共享区域中的 map 以获取数据。如何实现?

最佳答案

啊,刚注意到that other question也在你身边。

真的不想通过尝试将 C++ 代码直接嵌入 PHP 来使事情复杂化。

找出为什么从 PHP 页面生成的子进程不允许您访问共享内存的原因肯定比 简单。在最坏的情况下,使过程非常安全并且只是 call setuid 强制它模拟某个用户(假设是 UNIX 风格的主机)。不要不要将 setuid 设置为 root(这是安全禁忌)。

关于php - 如何在使用 Boost C++(在共享区域中)编写的 php Web 应用程序中读取 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27091585/

相关文章:

php - 无需刷新页面即可获取复选框值

c++ - xcode 项目中有多个 .cpp 程序?

c++ - 控制台应用去向c++

c++ - boost asio 读取/接收字节顺序

c++ - 使用 boost::shared_ptr<> 处理管理

php - 修改数据库时使用 Jquery 更新页面

php - 正则表达式在第一个换行符处拆分字符串

c++ - gcc 正弦和 boost 编译错误 :interval

php - 订单插入,同一个订单中的多个项目

c++ - 读取类变量