Use same shared memory unit from Lua and PHP

The closest I get in researching is stdin, stdout. But I don’t see how I can get it across two processes. I guess if I am running commands sequencially in the same terminal session, it could be done, but I do not see how to adapt that to my use case. I might be asking for the impossible which is why I haven’t found an answer.

I have a software that uses lua to parse data and can output json; I currently write that to a .json file.

Then a webpage, as .html or .php, running on localhost via a built-in php server (e.g. php -s localhost:8001) or what not, can read that .json file.

If I want the first program to be writing new output every second, that feels like excessive disc writing to burn out 86400 writes a day – somewhere in file size up to 30 kb in my higher end expectations. And the webpage keeps reading it repeatedly to get near realtime updates. Can I get this data transfer to be in RAM only between the two programs?

Maybe I am overthinking and it is moot as modern hardware will last decades even if being written over and over again every second. If that is the case, I can accept that answer and not worry about solving this cross-language cross-process puzzle.

I can only get stdin/out to work in the same terminal, e.g. in python (have not figured out lua stdin/out yet but should not be hard), and I can redirect that stdout into a file to then get the other program to access but I have no idea how to pass it directly to a webpage. Best bet is php I reckon.

This code doesn’t work. I set up a full fledged example based on the reading from comments by Robert who linked a lua and php discussion/documentation. Note, those are independent sources, so…

producer.lua

local shmem = require("shmem")
local mem = shmem.new(1024)
body = "some kind of test" 
mem:write(body) 

consumer.php

<?php 
$shm_id = shmop_open(0xff3,"c",0644,1024); 
if (!$shm_id) { echo "couldn't create shared memory segment`n"; } 
$shm_size = shmop_size($shm_id); 
$mystring = shmop_read($shm_id, 0, $shm_size); 
echo $mystring . "ipsum lorem" . $mystring 
shmop_close($shm_id); ?>  

And that is end of file. Of course the only thing output by php is ipsum lorem. I would have expected “some kind of testipsumloremsome kind of test”.