I lifted some code off of StackOverflow to test some very basic PHP / Python integration, as I would like to eventually create a web interface for a Python machine learning platform I've been testing for a while now.
The code is as follows below:
PHP:
<?php
$data = array('1', '2', '3');
$result = shell_exec('python "C:\Program Files (x86)\Zend\Apache24\htdocs\Machine-Learning-Python-Integration\phptransfertest.py" ' . escapeshellarg(json_encode($data)));
$resultData = json_decode($result, true);
var_dump($resultData);
?>
Python:
import sys
import json
try:
data = json.loads(sys.argv[1])
except:
print "ERROR"
sys.exit(1)
result = {'status': 'Yes!'}
print json.dumps(result)
But when I load this up in a browser, it only outputs NULL. I am unsure how to properly pass variables and files between Python and PHP, and most guides I have found tend to give me a NULL error.
shell_execis supposed to return NULL if something goes wrong with executing the command. What kind of string does. escapeshellarg(json_encode($data))create? Does this info help: stackoverflow.com/questions/12197815/…