For multiple running PHP scripts (10 to 100) to communicate, what is the least memory intensive solution?
- Monitor flat files for changes
- Keep running queries on a DB to check for new data
Other techniques I have heard of, but never tried:
- Shared memory (APC, or core functions)
- Message queues (Active MQ and company)
In general, a shared memory based solution is going to be the fastest and have the least overhead in most cases. If you can use it, do it.
Message Queues I don’t know much about, but when the choice is between databases and flat files, I would opt for a database because of concurrency issues.
A file you have to lock to add a line to it, possibly causing other scripts to fail to write their messages.
In a database based solution, you can work with one record for each message. The record would contain a unique ID, the recipient, and the message. The recipient script can easily poll for new messages, and after reading, quickly and safely remove the record in question.