在不了解你想要实现的目标的情况下,我会选择一个基本的http解决方案,用python启动一个简单的http服务器
import SimpleHTTPServer import SocketServer PORT = 8000 Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(("", PORT), Handler) print "serving at port", PORT httpd.serve_forever() .... do something with the http request and send the response
然后php脚本可以直接向python做一些GET / POST / etc ..请求,并获取http响应,例如通过cURL:
// create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, "localhost"); // set port curl_setopt($ch, CURLOPT_PORT, 8000); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); // close curl resource to free up system resources curl_close($ch);
当然这是一个简单的存根,它应该稍微调整一下,但它应该给你一个起点。