Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using shared memory with php and c?

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

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

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

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

like image 325
JDustin Avatar asked Jun 22 '26 15:06

JDustin


1 Answers

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

From the PHP manual:

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).

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.

like image 61
Emil H Avatar answered Jun 24 '26 05:06

Emil H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!