shared memory? Does it exist in PHP? |
I have an architectural question. Does Codeigniter or PHP have any functionality for interprocess communication? Here is what I mean by this. I am spawning multiple copies of a controller called back_end. Each time a message comes over CORs I spawn a controller by sending https://URL/back_end/myFunc(). They start up fine, do their thing, and go away. I'd like each of those copies to be able to read and write a single area of shared ram (the way we used to do it in the mini days). My server, btw is running Ubuntu.
Now I could get use linked list built in shared Ram or maybe another one of the other IP communication constructs.
proof that an old dog can learn new tricks
Well I found it; shmop. For those with inquiring minds: http://php.net/manual/en/ref.shmop.php. But I am a little concerned about having to write this. My app is driven by a user on Chrome. Whenever they decide to write out some data they can by pulling down an extension. This causes the writing of data via XMLHTTP which "spawns" (is that word still in fashion?) a process on the server. So, five people writing their data, causes 5 new process on the server. Each only lasts for a few mseconds, writes out their data to mySQL and exits. This is a multi-process model.
The problem is that each one of these 5 buffers accidently appears as 2 buffers to the server. Thus 5 buffers spawn 10 processes. The reason for these two buffers is not really clear and is being investigated. Not a huge throughput deal for me with the low number of users that I expect. But what happens, since each process knows nothing about the other processes and the data is written twice; once for the real buffer and once for the ghost buffer. It works this way 100% of the time. I can see two of the exact same records in the mysql database (and also in dynamoDB for long term archival). What I'd really like to do is recognize that only the first buffer is valid, and ignore the second. But since this is multi-process and is a stateless machine, each process knows nothing about the past. Multi-thread sure would be easier, but whatever. So these processes need to communicate. The process that is spawned by buffer A, needs to ignore buffer B. Or if it gets buffer B, it needs to respond back to the Chrome caller with a noop and then flush the buffer. I am not sure how to do this. I tried setting a cookie with the first process when buffer A came in which would let the process spawned by buffer B know "I already got this one" so ignore it. But it seems that cookies are not fast enough. It seems to take some time for the cookies to propogate. I wish I understood cookies better. Then I was thinking shared memory since it is really fast, but I would need to build that from scratch. So that leaves me thinking, there must be some tool out there that would help me solve this problem. Does anyone know of any type of php based inter-process communication tool?
proof that an old dog can learn new tricks
Why not just write the information to PHP Static Variables?
OR you could write a Registry Class, I wrote a Registry Class to store common things I need in my apps. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Hi Insite. This is what I ended up doing and it seems to be working. The idea is to block a second buffer from the same user for 1 sec.
if(is_null($_SESSION[$email_keye])){ $this->session->set_tempdata($email_keye, 'value', 1); //block for 1 sec } //noyes, so write it else { $json=json_encode(html_escape("record written\n")); header('Content-type: application/json'); header("Access-Control-Allow-Origin: *"); echo ($json); exit; } I don't know what a PHP static variable is. As I think I mentioned, the variable needs to be static globally on the server. If this method I came up with fails, I'll try it out.
proof that an old dog can learn new tricks
|
Welcome Guest, Not a member yet? Register Sign In |