Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signalling inside php

hi when implementing a connection that stays open for a long time ( comet ), how would i implement signalling between php proses(outstanding requests)??

example timeline:

  • request 1 start
  • request 1 makes action
  • request 1 sleeps
  • request 2 start
  • request 2 makes action
  • request 2 notifies request 1 and go's to sleep
  • request 1 wakes up and sends the new data
  • request 1 sleeps agen

i was wandering if ther was a methode whitch use less(noting?) cpu prosessing

like image 705
borrel Avatar asked Oct 11 '22 01:10

borrel


1 Answers

If your platform is Linux/Unix, you can use queues.

  • request 1 start
  • request 1 makes action
  • request 1 sleeps and reading queue (sleep(1) and read queue)
  • request 2 start
  • request 2 makes action
  • request 2 sending message to queue
  • request 1 receives message from queue, wakes up and sends the new data
  • request 1 sleeps again

Whith semaphores you can do this without sleep() even, but it will be more difficult to code.

like image 58
OZ_ Avatar answered Oct 14 '22 05:10

OZ_