2014-11-23 13 views
1

我已經使用共享區域中的C++ Boost庫編寫了一個映射(鍵,值)。如何閱讀使用Boost C++(在共享區域)編寫的php web應用程序中的地圖?

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應用程序,並希望閱讀共享區域地圖來獲取數據。如何實現它?

+0

您需要在C++中實現並將擴展模塊暴露給PHP。換句話說,更好地區分你的擔憂,因爲你不想這樣做(相反,例如,製作一個可以從PHP使用的網絡API?)。如果你還好奇:http://www.php-cpp.com/ – sehe 2014-11-23 20:41:19

回答

1

啊,剛纔注意到that other question也是你的。

確實不想通過嘗試將C++代碼直接嵌入到PHP中來使事情複雜化。

它一定是更容易找出爲什麼從PHP頁面產生的子進程不允許您訪問共享內存。在最糟糕的情況下,要使該過程非常安全,並且只需要強制它模擬某個用戶(假設爲UNIX風格的主機)。做不是 setuid到根(這是一個安全no-no)。

相關問題