Can someone provide me links or snippets where a PHP process writes to memory and a Java process reads from the shared memory?
Thanks for the wonderful answers.
Edited question :
Suppose i create a shared memory in php like this
<?php
$shm_key = ftok(__FILE__, 't');
$shm_id = shmop_open($shm_key, "c", 0644, 100);
$shm_bytes_written = shmop_write($shm_id, $my_string, 0);
?>
Now is there some method by which i can pass the value of $shm_id and then read from it in java.
If you don’t need synchronized interaction between Java and PHP – I would use memcached, membase or some other type of memory key store.
Another way, for huge amount of data stream, is using Unix named pipe (FIFO). It is common way in IPC (Inter Process Communication).
First create the pipe as normal file using
mkfifocommand. Add some reasonable access rights. In PHP open the pipe withr+mode as normal file and write, finally close. On Java side you keep it open as normal file and read continuously byFileInputStreamwith blockingread/readlineor nonblocking NIO.In comparison to SHM, you don’t have to play with JNI, shared memory synchronization, ring buffer implementations, locking and memory leaks. You get simple read/write and FIFO queue at lowest development cost.
You delete it as normal file. Don’t use random access or
seekas it is real stream without history.