简体   繁体   English

PHP和Java的生产者使用者

[英]Producer Consumer in PHP and Java

I have a system where in I get requests via HTTP call to my PHP code(producer). 我有一个系统,可以通过HTTP调用对我的PHP代码(生产者)的请求。 This code adds the request parameters to a table in MYSQL(queue). 此代码将请求参数添加到MYSQL(queue)中的表中。 This is then taken and processed by a java program(consumer). 然后由Java程序(消费者)获取并处理。 In my first implementation both producer and consumer was in PHP(with MYSQL queue). 在我的第一个实现中,生产者和使用者都使用PHP(带有MYSQL队列)。 Then as load increased this proved inefficient and so I made the consumer java. 然后,随着负载的增加,这被证明是效率低下的,因此我选择了使用者java。 Now I think polling MYSQL table for the queue from my java app is getting inefficient(vey high cpu usage for MYSQL process). 现在,我认为从我的Java应用程序查询队列的MYSQL表效率低下(MYSQL进程的CPU使用率很高)。 Is there a better way to implement this queue (sharing memory between PHP code and Java app or something)? 有没有更好的方法来实现此队列(在PHP代码和Java应用之间共享内存)?

Yes, you've got many options. 是的,您有很多选择。 The first is obviously to convert this into a client-server service, and pass either text or binary messages between them. 首先显然是将其转换为客户端服务器服务,并在它们之间传递文本或二进制消息。 You might want to look into webservices if you're a masochist, or a simpler REST service, or CORBA / COM+ and other for binary serializations. 如果您是受虐狂,或更简单的REST服务,或者CORBA / COM +和其他用于二进制序列化的服务,则可能需要研究Web服务。 And then there's various queues, like MQseries, RabbitMQ, etc. Sometimes the middle-man is fast enough and efficient enough, or a direct call would suffice. 然后是各种队列,例如MQseries,RabbitMQ等。有时中间人足够快和足够高效,或者直接调用就足够了。

The next is a more direct link if your platforms are within the same server or cluster, something like JavaBridge and others (do a search for "java php bridge", and several will crop up. There's even a PHP interpreter written in Java for the JVM which gives you full compatibility between the two which might do the trick for you. 如果您的平台位于同一服务器或群集中,则下一个链接是更直接的链接,例如JavaBridge等(搜索“ java php bridge”,并且其中一些会出现。甚至还有用Java编写的PHP解释器) JVM为您提供了两者之间的完全兼容性,这可能会帮您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM