How to call Python function in PHP passing variable argument
<p>I'm calling the function using 'exec' and defining the argument as a variable.</p>

<pre><code>$jsonrequest = escapeshellarg(json_encode($request, JSON_NUMERIC_CHECK));
$solveroutput = exec('sudo python /var/www/website.com/services/run.py $jsonrequest');
</code></pre>

<p>I have already  tried to call like this:</p>

<pre><code>$solveroutput = exec("sudo python /var/www/website.com/services/run.py '$jsonrequest'");  
</code></pre>

<p>and</p>

<pre><code>$solveroutput = exec("sudo python /var/www/website.com/services/run.py $jsonrequest");  
</code></pre>

<p>and also without 'sudo'  </p>

<p>When I call the function directly in command line in the server (AWS), I receive the result, as following. <code>$jsonrequest</code> above is exactly the way I'm typing in command line.</p>

<pre><code>[lsenna@ip ~]$ sudo python /var/www/website.com/services/run.py '{"max_split":4,"order":681,"max_cost_frac":0.1,"items":[{"productid":8745,"qty":1,"estimatedprice":53.6}],"bids":[{"vendorid":1,"minimum_order":0,"items":[{"productid":8745,"qty":1,"estimatedprice":100}]}]}'
</code></pre>

<p>RESPONSE:</p>

<pre><code>{"status": "OK", "order": 681, "deliveries": [{"vendorid": 1, "productid": 8745}]}
</code></pre>

<p>Thanks!</p>