[英]Passing data between running PHP scripts
For multiple running PHP scripts (10 to 100) to communicate, what is the least memory intensive solution? 要使多个运行中的PHP脚本(10到100个)进行通信,什么是最少内存占用的解决方案?
Other techniques I have heard of, but never tried: 我听说过但从未尝试过的其他技术:
This is hard to answer without knowing: 不知道就很难回答:
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. 在PHP环境中,使用数据库可能是最容易设置的,并且取决于每分钟有多少个查询和这些查询的类型,这实际上可能是最明智的解决方案。 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. 但是,同样,如果没有有关该应用程序的更多信息,很难确定。
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. 该记录将包含唯一的ID,收件人和消息。 The recipient script can easily poll for new messages, and after reading, quickly and safely remove the record in question. 收件人脚本可以轻松轮询新邮件,阅读后可以快速安全地删除有问题的记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.