我在共享区域中使用 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/