RedPaladin
Posts: 9
Joined: Fri Jun 19, 2015 2:15 pm

Php running two python scripts

Fri Jul 31, 2015 12:15 pm

Hello Community,

I have been working on a project that controls 2 Stepper Motors remotely. I am having a problem running a php code when I push a button on my IP-based website.

Code: Select all

var/www/Stepperforward.php
<?php
    system("sudo python /var/www/Stepper1.py & /var/www/Stepper2.py");
?>
If I run this in the php code in the Pi terminal both motors start at the same time which is what I want. If, however, I run this in the web browser so it looks like:

Code: Select all

192.168.40.1/Stepperforward.php
It will only run the first program. So in this case it will only run Stepper1.py. The python code behind the two programs implements a while loop. It still baffles me that I can get both motors in the Pi terminal, but the second I try it in a web browser it only runs the one motor.

If I need to explain myself more, I am more than willing to do so. Thanks in advance for any help!

-RedPaladin
Last edited by RedPaladin on Fri Jul 31, 2015 12:31 pm, edited 1 time in total.

Heater
Posts: 16091
Joined: Tue Jul 17, 2012 3:02 pm

Re: Php running two python scripts

Fri Jul 31, 2015 12:30 pm

You don't have a closing close quote and the end of the system command.

Also shouldn't the command be:

system("python /var/www/Stepper1.py & python /var/www/Stepper2.py &");

I don't think the Apache should be using sudo. Just make sure everything has the right permissions set so that it can be run by Apache.
Last edited by Heater on Fri Jul 31, 2015 12:50 pm, edited 1 time in total.
Memory in C++ is a leaky abstraction .

Heater
Posts: 16091
Joined: Tue Jul 17, 2012 3:02 pm

Re: Php running two python scripts

Fri Jul 31, 2015 12:48 pm

I presume when you say you have a "while loop" in your python that it is intended to loop forever.

I think you will have the problem that after starting both of those in the background the php script will run to it's end and exit. At that point both background tasks will be terminated.
Memory in C++ is a leaky abstraction .

Return to “Other programming languages”