How to read map in php web application written usi

2019-03-01 10:36发布

问题:

I have written one map (key, value) using C++, Boost library in shared region.

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);             
}

Creating memory map in shared region:

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));
 }

Now I am developing one web application using PHP and want to read map in shared region to get the data. How to implement it?

回答1:

Ah, just noticed that other question was also by you.

You really do not want to complicate the matter by trying to embed the C++ code directly into PHP.

It is bound to be far simpler to find out why the child process spawned from a PHP page doesn't allow you to access shared memory. In the worst possible case, make the process very secure and just call setuid to force it to impersonate a certain user (assuming a UNIX-flavoured host). Do not setuid to root (this is a security no-no).



标签: php c++ boost