用PHP和C共享内存? [英] using shared memory with php and c?

查看:84
本文介绍了用PHP和C共享内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用共享内存在Windows中的php脚本和c程序之间进行通信吗?

Can you use shared memory to communicate between php scripts and c program in windows?

c程序始终运行,并使用内存映射文件,即:

The c program runs all the time and uses memory mapped files ie:

handle1 = CreateFileMapping(
 (HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0, sizeof(byte)*BUFFER_SIZE, "my_foo" );

hView = (LPINT) MapViewOfFile(handle1, FILE_MAP_ALL_ACCESS, 0, 0, 0);

对于PHP脚本,我可以仅使用以下代码打开由c程序创建的内存映射文件吗?

For the PHP scripts can I just use the below code to open the memory mapped file created by the c program?

$shmkey = @shmop_open(ftok("my_foo", 'R'), "a", 0644, $buffer_size);

还是c内存映射文件和php共享内存不同?

or are c memory mapped files and php shared memory different things?

推荐答案

PHP shmop函数只是底层

The PHP shmop functions are just wrappers for the underlying POSIX functions, which doesn't seem to be available under windows.

PHP手册:

注意:Windows 2000之前的Windows版本不支持 支持共享内存.在Windows下, Shmop仅在PHP为 作为Web服务器模块运行,例如 作为Apache或IIS(CLI和CGI不会 工作).

Note: Versions of Windows previous to Windows 2000 do not support shared memory. Under Windows, Shmop will only work when PHP is running as a web server module, such as Apache or IIS (CLI and CGI will not work).

PHP显然在apache中模拟了这种行为,但是由于它在独立的二进制文件中不可用,因此几乎不会与Windows等效项集成.

Appearently PHP emulates this behaviour within apache, but since it isn't available in the stand alone binaries it will hardly integrate with the windows equivalents.

这篇关于用PHP和C共享内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆