Search code examples
phpmultithreadingqueueipcfifo

FIFO to communicate between threads


I've got a file with mail adresses to which I want to send an email.

I've splitted the jobs between

  • one task which reads the file
  • x others tasks that send emails

To communicate between the first task and the others, I thought that using FIFO (thanks to posix_mkfifo) would be a great idea, with one FIFO per "sending task", and cycle through them. Since I sometimes need to stop the script, I save the offset of the adresses file after each read (in the first task).

The problem is when I close the FIFO, the offset can be at the 500th row (so 500 adresses read and sent throughs FIFO) but maybe tasks have processed only 5 rows each. How can I prevent the close of the FIFO on the writer side from stopping the other tasks to let them process their queues ?


Solution

  • i was able to resolve my problem by opening the fifo in read/write instead of only read on the second task