Because PHP does not support multi-threading, I want to use Python to do one.
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 call". $num. " Times ";
echo $num +=1;
};
if (Isset ($method) && $method! = "") {
$method ();
}else{
echo "No function to call";
}
subprocess explanation
2.python Multithreading
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 am at the movies! %s "%ctime ()
Sleep (5)
if__name__== ' __main__ ':
Music ()
Move ()
Print "All over%s"%ctime ()
From: http://bbs.php-z.com/thread-3091-1-1.html
Python calls PHP functions