python调用php函数

由于php不支持多线程,所以想借助python搞一个。
1.import subprocess
import time
#Simple caller, disguard output
method="diao"
for i in range(2):
time1=time.time()
#print i
#subprocess.call("php h.php")
proc = subprocess.Popen("php h.php " + method, shell=True,stdout=subprocess.PIPE)
response = proc.stdout.read()
time2=time.time()-time1;
print time2
print response
time.sleep(1)

php
$method = $argv[1];

function diao(){
static $num;
echo " ";
echo "php调用".$num."次";
echo $num+=1;
};
if(isset($method) && $method != ""){
$method();
}else{
echo "No function to call.";
}
subprocess讲解


2.python 多线程
fromtimeimportctime,sleep
def music():
      for i in range(2):
          print"I was listening to music. %s"%ctime()

          sleep(1)
def move():
       for i in range(2):
              print"I was at the movies! %s"%ctime()
              sleep(5)
if__name__=='__main__':
     music()
     move()
     print"all over %s"%ctime() 

来自:http://bbs.php-z.com/thread-3091-1-1.html

原文地址:https://www.cnblogs.com/yhdsir/p/5536545.html