美文网首页
python调用php函数

python调用php函数

作者: 我在太行山下 | 来源:发表于2016-05-10 09:55 被阅读0次

    由于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 "\n";

    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() 

    相关文章

      网友评论

          本文标题:python调用php函数

          本文链接:https://www.haomeiwen.com/subject/crxyrttx.html