Robin Rodricks
Robin Rodricks

Reputation: 113976

Passing data between running PHP scripts

For multiple running PHP scripts (10 to 100) to communicate, what is the least memory intensive solution?

Other techniques I have heard of, but never tried:

Upvotes: 0

Views: 566

Answers (2)

Pekka
Pekka

Reputation: 449435

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.

Upvotes: 2

Vinko Vrsalovic
Vinko Vrsalovic

Reputation: 340241

This is hard to answer without knowing:

  • How much data will they send in each message (2 bytes or 4 megabytes)?
  • Will they run in the same machine? (This looks like a yes, else you wouldn't be considering shared memory)
  • What are the performance requirements (one message a minute or a zillion per second)?
  • What resource is most important to you?

And so on...

Using a DB is probably easiest to setup in a PHP environment and, depending on how many queries per minute and the type of those queries, that might indeed be the sanest solution. Personally I'd try that first and then see if it's not enough.

But, again, hard to tell for sure without more information on the application.

Upvotes: 2

Related Questions