简体   繁体   English

从PHP调用Python脚本

[英]Calling a Python Script from PHP

I am trying to call a python script from my PHP page but no output is being delivered. 我试图从我的PHP页面调用python脚本,但没有输出。 Is there any error in code ? 代码中是否有错误?

<?php
include('main.php'); 
$lat = $_POST['lt'];
$lon = $_POST['ln'];
$uid = $_POST['id'];
$rad = $_POST['rd'];

$outs = 'python recommend.py ' . $uid . ' ' . $lat . ' ' . $lon . ' ' .     $rad;
$output = shell_exec($outs);
echo $output;
?>

Whereas I tried to get the output using dummy variables, it is being shown. 虽然我试图使用虚拟变量获得输出,但它正在显示。

<?php
$lat = $_POST['lt'];
$lon = $_POST['ln'];
$uid = $_POST['id'];
$rad = $_POST['rd'];
echo        "11,28.720663,77.106192,1.18764869157,50.2058551405~12,28.705344,77.147270,2.854    76982119,2.42050298022~14,28.697590,77.143108,2.63211107261,13.1314821232~64,28.        683058,77.079048,2.10283926574,28.9526789043~66,28.670294,77.126684,2.8317092358    ,5.80484607006~67,28.677712,77.092713,1.95077211146,28.4871314757~68,28.665512,7    7.093081,2.76955528898,21.8407451837~71,28.674069,77.124547,2.53467055409,24.755    4907651~"
?>

My guess is that you need to provide the full path to the python script, ie: 我的猜测是你需要提供python脚本的完整路径 ,即:

python /full/path/to/recommend.py

As mentioned on my comments, in order to properly debug php , you'll need to enable error reporting at the top of your php scripts , ie: 正如我在评论中提到的,为了正确调试php ,你需要在php脚本的顶部启用错误报告 ,即:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
//the rest of your code...

Comment on production mode. 评论生产模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM