ここに私の問題があります.phpからpythonスクリプトに変数を送信する必要がありますが、これはそれほど難しいことではありませんが、それらが同じサーバー上にないことがわかりました。php ファイルはサーバー A にあり、server-a.com でアクセスできます。python は別のサーバーにあり、server-b.com でアクセスできます。
これは、同じサーバー上にあるときに機能するphpとpythonの現在のコードです。
PHP:
// Call to the python script test.py with the JSON data
$result = shell_exec('python test.py ' . escapeshellarg(json_encode($data)));
// get data back from python, decode it and display it
$resultData = json_decode($result, true);
//var_dump($resultData);
echo $result;
?>
パイソン:
import sys, json
# Load the data that PHP testv2.php sent us
try:
data = json.loads(sys.argv[1])
except:
print "ERROR"
sys.exit(1)
# Generate some data to send to PHP
result = {'status': 'Yes!'}
# Send it to PHP
print json.dumps(data)