您可以使用redis(例如pub/sub特性)作为进程间通信工具。在Redis is an open source (BSD licensed), in-memory data structure
store, used as a database, cache and message broker. It supports data
structures such as strings, hashes, lists, sets, sorted sets with
range queries, bitmaps, hyperloglogs and geospatial indexes with
radius queries. Redis has built-in replication, Lua scripting, LRU
eviction, transactions and different levels of on-disk persistence,
and provides high availability via Redis Sentinel and automatic
partitioning with Redis Cluster.
除了通过redis实现IPC外,还可以作为分布式的键值数据库使用,这是redis imho的一大优势。在
另一个选择-zeromq-进程间通信的最著名的工具之一。网上有很多关于它的教程和文档。原始指南:http://zguide.zeromq.org/page:allØMQ (also known as ZeroMQ, 0MQ, or zmq) looks like an embeddable
networking library but acts like a concurrency framework. It gives you
sockets that carry atomic messages across various transports like
in-process, inter-process, TCP, and multicast. You can connect sockets
N-to-N with patterns like fan-out, pub-sub, task distribution, and
request-reply. It's fast enough to be the fabric for clustered
products. Its asynchronous I/O model gives you scalable multicore
applications, built as asynchronous message-processing tasks. It has a
score of language APIs and runs on most operating systems. ØMQ is from
iMatix and is LGPLv3 open source.
官方指南中的PHP服务器和python客户端的简单示例:
PHP服务器:<?php
/*
* Hello World server
* Binds REP socket to tcp://*:5555
* Expects "Hello" from client, replies with "World"
* @author Ian Barber
*/
$context = new ZMQContext(1);
// Socket to talk to clients
$responder = new ZMQSocket($context, ZMQ::SOCKET_REP);
$responder->bind("tcp://*:5555");
while (true) {
// Wait for next request from client
$request = $responder->recv();
printf ("Received request: [%s]\n", $request);
// Do some 'work'
sleep (1);
// Send reply back to client
$responder->send("World");
}
Python中的Hello World client:
^{pr2}$