How to run from PHP > Python > Matlab > Python > PHP


I'm trying to have PHP run a python script that runs matlab code. I want the matlab output (the value 7.5) to come back to PHP and output to the browser.

When I run my python script from the terminal, it successfully runs the matlab code.

When I run the python script from PHP, it does not output the matlab result to the browser. I should have "7.5" appear in the browser.

If I change the python code to just print something, then I get the correct output in the browser.

I suspect that I'm having an issue with permission, but I've given all of the files RWX permission to all.

HTML code

<form action='ts.php' method='POST' enctype='multipart/form-data'>
<input type='submit' name='matlab_plot' value='Plot in Matlab'>

PHP code

$command = escapeshellcmd('/Applications/XAMPP/xamppfiles/htdocs/CS85_Project/troubleshoot/ 2>&1');
$output = shell_exec($command);
echo $output;

Python code

import matlab.engine
eng = matlab.engine.start_matlab()
a = eng.workspace['a']
print a

Matlab code

b = 5;
h = 3;
a = 0.5*(b.* h);

EDIT: I have found that the python script stops running ateng = matlab.engine.start_matlab() when called from PHP. I still don't have a solution to this problem, but my question is: why can't PHP run this python function?

People are also looking for solutions to the problem: forms - PHP Session destroy twice?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.