php向python提交数据类型,从PHP向Python脚本发送数据

您可以使用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}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值