signalling inside php signalling inside php multithreading multithreading

signalling inside php


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.


I believe you would have to use pcntl_signal(), along with pcntl_fork(). The server would have to support forking though.

As for the cpu processing load use usleep() in the loop so that the processor has time to be used by other processes.


ideally, I would write this with the requests or "jobs" for the purposes of this being written to a database.

script 1 does something and writes a "job" to the DB
script 1 sleeps for an interval, then checkes to see if there is a returncode for that job in the DB, if so then
act
else sleep/repeat

script 2 checks for uncompleted jobs in the DB
if so then
act and write returncode
else sleep/repeat