无法访问 PHP/C++通过网络共享内存
我在 C++ 和 PHP 之间共享一些内存
在 PHP 端我有:
$inputshm_id = shmop_open($shid, "w", 0777, 1024);
其中 shid 是我用 ftok 创建的标识符。
当我在服务器上以 root 身份运行这个 PHP 脚本时,这一切都工作正常,但是当我尝试通过网络远程运行它时,我得到:
警告:shmop_open()[function.shmop-open]:无法附加或创建共享/var/www/html/prof/phpsm.php 第 6 行中的内存段
...其中第 6 行是我上面显示的行。
由于当我以 root 身份从服务器运行它时,一切都运行良好,因此我假设某个地方阻止了 Web 用户请求连接到共享内存。
有谁知道这可能是什么原因造成的?
谢谢
I am sharing some memory between C++ and PHP
At the PHP end I have:
$inputshm_id = shmop_open($shid, "w", 0777, 1024);
Where shid is an identifier I created with ftok.
This all works fine when I run this PHP script logged in as root on the server but when I try to run it remotely over the web I get:
Warning: shmop_open() [function.shmop-open]: unable to attach or create shared memory segment in /var/www/html/prof/phpsm.php on line 6
...where line 6 is the line I've shown above.
Since it all runs fine when I run it from the server as root I'm assuming something somewhere is preventing web user requests from connecting to the shared memory.
Does anyone know what could be causing this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 SELinux 阻止了 shm 访问(您可以通过运行
setenforce 0
进行验证,测试,然后运行 setenforce 1
),但我不知道一个好的方法除了修改策略或切换到 mmap 之外,还有其他解决方法。The issue is that SELinux is blocking the shm access (you can verify by running
setenforce 0
, testing, and runningsetenforce 1
after), but I don't know a good way of solving it other than modifying the policy or switching to mmap.只是为了添加已接受的答案,我需要将 SELinux 保持在强制模式,因此我最终执行了以下操作以允许访问 PHP 中的共享内存操作:
我最终确实经历了几次迭代才得到正确的结果,但是我对 CentOS 6 的最终政策是:
Just to add to the accepted answer, I needed to keep SELinux in enforcing mode, so I ended up doing the following to allow access to shared memory operations in PHP:
I did end up going through a couple iterations of this to get it right, but my final policy on CentOS 6 was: