php和python的通信,memcacheq 中php 和python的通信

php 代码

php_queue_test.php

1 <?php

2 $me = new Memcache;

3 $me->connect("127.0.0.1", "22202") or die;

4 $count = 1;

5 while(true) {

6 $queue_name = "q2";

7 $hello = 'hello,I\'m beck'.$count;

8 memcache_set($me, 'q2', $hello, 0, 0);

9 $count ++;

10 sleep(1);

11 }

12 ?>

php php_queue_test.php

python 代码

py_queue_test.py 1 #!/usr/bin/env python

2 #-*- coding:utf8 -*-

3

4 import sys

5 import time

6 import random

7

8 import memcache

9

10 mc = memcache.Client(["%s:%s"%("127.0.0.1", "22202")])

11 queue_name = "q2"

12 def putter():

13 count = 0

14 while True:

15 data = "{url:aad, type:curl}hello%d"%(count)

16 mc.set(queue_name, data)

17 print "put ", data

18 count += 1

19 time.sleep(random.randint(1, 10))

20

21 def process_data(data):

22 print "processing data :", data

23

24 def getter():

25 while True:

26 data = mc.get(queue_name)

27 if data:

28 process_data(data)

29 else:

30 print "no message, sleep for a while ..."

31 time.sleep(10)

32

33 if __name__ == "__main__":

34 if len(sys.argv) != 2:

35 print "Wrong arg numbers"

36 else:

37 cmd = sys.argv[1]

38 if cmd == "put": putter()

39 elif cmd == "get": getter()

40 else: print "wrong cmd"ptyhon  py_queue_test.py  get

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值