I have PHP server, in which I need to update client A about some client B action, at the moment it’s done. How it is normally being accomplished ?
My current solution would be:
- A leaves an open
$.ajax(...).done(function myCallBack(){...});call for this. - when A is in
myCallBack(){...}it issues another$.ajax(...).done(function myCallBack(){...});. This way the communication with server stays open for receiving new info anytime - the PHP would have to continually check for inter-session communication file to transfer data to/from two concurrent sessions
Leaving $.ajax(...).done(function myCallBack(){...}); open (and spawning new ones all the time) is the way to do it ?
For inter-session communication – is there a way to signal events or something like that (instead of continuously monitoring some file [a waste of resources!]) ?
This is how I solved it:
Client A leaves an open
ajaxcall:$.ajax(...).done(function myCallBack(){...});: on the PHP server side (session), A locks on asemaphoreusingsem_acquire($semaphore_A), and waits.Client B removes semaphore
$semaphore_Ausingsem_remove($semaphore_A), thus releasing A that returns to client JS callbackmyCallBack().Of-course, it’s very simplistic, and I use shared-memory (e.g.
shm_attach()) to exchange status and data between processes.For other developers stuck with this technique:
what took me so long to debug it, is the fact the I opened a session (
session_start()) and didn’t close it (session_ write_ close()) – which locked other processes and prevented any concurrency !