0
了PHP腳本的exec我從一個PHP一個由exec命令接收空的結果執行python腳本。如果我從shell執行python命令,它正確返回正確的結果,以及日誌沉默;這是我的PHP函數:蟒蛇返回空字符串
public function poll($palina){
//set_include_path("/var/www/html/iPhone/inarrivo/python");
$pythonCommand="python3.4 ../../python/palina.py $palina";
$result=exec($pythonCommand);
echo "<blank>command=$pythonCommand result=$result</blank>";
$resultData = json_decode($result, true);
if (!is_array($resultData)) {
error_log($resultData);
$resultData=Array();
}
//print_r($resultData);
return $resultData;
}
這就是所謂的python腳本:
#!/usr/local/bin/python3.4
# change above line to point to local
# python executable
from xmlrpc.client import Server
from pprint import pprint
import sys, json
import datetime, time
palina=sys.argv[1]
DEV_KEY = 'UuC378Q3l3Y4vtF8q2Hj3i5Up6OmZKb2'
s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')
token = s1.autenticazione.Accedi(DEV_KEY, '')
res = s2.paline.Previsioni(token, palina, 'it')
#pprint(res)
arrivi=res.get('risposta').get('primi_per_palina')[0].get('arrivi')
myList=[]
for arrivo in arrivi:
if 'nessun_autobus' not in arrivo and 'non_monitorata' not in arrivo:
output={}
acapolinea=arrivo.get('a_capolinea')
output["busDestination"]=arrivo.get('destinazione')
output["wait"]=arrivo.get('annuncio')
if output["wait"]=='In Arrivo':
output["receiving"]=1
else:
output["receiving"]=0
meb=arrivo.get('meb')
output["busNumber"]=arrivo.get('linea')
output["busLines"]=arrivo.get('id_percorso')
output["time"]=arrivo.get('tempo_attesa')
output["stops"]=int(arrivo.get('distanza_fermate'))
output["palina"]=arrivo.get('id_palina')
output["inarrivo"]=arrivo.get('in_arrivo')
partenza= arrivo.get('prossima_partenza')
if acapolinea == 1:
output["receiving"]=2
output["acapolinea"]=acapolinea
if partenza:
s = datetime.datetime.strptime(partenza.value, "%Y%m%dT%H:%M:%S")
output["capolineaDate"]=s.strftime('%H:%M')
myList.append(output)
print (json.dumps(myList));
該腳本前面的服務器上運行良好。是否有一些配置將在CentOS設置有PHP和Python的正確集成?