Search code examples
pythonphpxampp

Sending output of python to PHP webpage


Below is my code in Python. My lecturer requested me is that possible to send the fanspeed.output['fan'] to PHP. For example, I created a webpage on xampp then I need to send the output of the python to the webpage which will display the output on the webpage. I searched online and I could not find a working way to solve it. Can anyone help, please?

temp = int(input("temp="))
hum = int(input("hum="))
fanspeed.input['temperature'] = temp
fanspeed.input['humidify'] = hum
fanspeed.compute()
fanspeed.output['fan']
fan.view(sim=fanspeed)
print("Fan speed =",fanspeed.output['fan'])

Solution

  • The easiest way is to call the python script via a shell_exec.

    Something like this

    <?php
    echo shell_exec("python /path/to/your/python/script.py");