Python“脚本”的PHP执行
这适用于执行工作并返回输出的脚本,不适用于 CherryPy。
<?php
// execute your Python script from PHP
$command = escapeshellcmd('myPythonScript.py');
$output = shell_exec($command);
echo $output;
// take response content to embed it into the page
?>
PHP 访问 Python/CherryPy 服务的网站
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
这会以http://localhost:8080 开头,您应该会看到Hello world!。
现在您可以通过 localhost:port 访问 CherryPy 的输出。
性能不好,但可以。
<?php
$output = file_get_contents('http://localhost:8080/');
echo $output;
?>
Joomla + Ajax 访问 Pyhton/CherryPy 服务的网站
另一种解决方案是,不使用 PHP 来获取内容,而是从客户端进行获取。基本上,您将使用 Ajax-Request 到 CherryPy 服务的网站,以获取其内容并将其嵌入到 Joomla 服务页面的 dom 中。
// add jQuery Ajax reqeust from your Joomla page to CherryPy
$.ajax({
url: "https://localhost:8080/", // <-- access the 2nd served website
type: 'GET',
success: function(res) {
//console.log(res);
alert(res);
$("#someElement").html(res);
}
});