How to communicate between concurrent sessions in PHP and JS?

I have a PHP server in which I need to update client A about some action of client B, this is currently done. How is this usually done?

My current solution:

  • A leaves an open call $.ajax(...).done(function myCallBack(){...});for this.
  • when A is in myCallBack(){...}, it issues another $.ajax(...).done(function myCallBack(){...});. Thus, communication with the server remains open to receive new information at any time.
  • PHP will need to constantly check the intersessional communication file to transfer data to / from two simultaneous sessions.

Exiting $.ajax(...).done(function myCallBack(){...});open (and spawning new ones all the time) is a way to do this?

For intersessional communication - is there a way to signal events or something like that (instead of constantly monitoring a certain file [a waste of resources!])?

+5
source share
2 answers

Here's how I solved it:

Client A leaves an open call ajax:: $.ajax(...).done(function myCallBack(){...});on the server side of PHP (session), A is blocked on semaphore, using sem_acquire($semaphore_A)and waiting.

Client B removes the semaphore $semaphore_Awith sem_remove($semaphore_A), thereby freeing A , which returns the client JS callback myCallBack().

, , shared-memory (, shm_attach()) .

, :

, , , (session_start()) (session_ write_ close()) - concurrency!

+2

A , B , . , B .

+1

All Articles