Trevader2413
Trevader2413

Reputation: 86

How can I kill an infinite PHP process?

I am using a raspberry pi to learn from and to experiment with, and I made a program that simply flashes an LED on GPIO pin 29 (with wiring pi) on a pi B+. I made this process infinite with the intention of killing it with another button on my webpage, but I can't figure it out. I can't even seem to stop it SSHing to the pi. this isn't a real problem, because I can restart the pi and turn it off, but it would be good to learn. I want to kill it from my webpage (I'm using an apache server). here's the code:

<?php
   system ( "gpio mode 29 out" );
   while (true){
   system ( "gpio write 29 0" );
   sleep(1);
   system ( "gpio write 29 1" );
   sleep(1);
   header('Location: remoteGPIO.html');
}
?>

so can I kill this with another button NOT using javascript? I don't mind using it, but I would like to avoid it. It's no big deal if I can't though. I start it using this button:

<form action="GPIO29FLASH.php"><button>begin</button></form>

thanks in advance!

Upvotes: 1

Views: 142

Answers (1)

DannyPhantom
DannyPhantom

Reputation: 1063

A good idea might be to use session. Make the end button to go to another php script that will set some session variable to true. Now make your current script to flash once and then reload the page. And if the session variable is set - simply terminate the script. It might even work without reloading the page by changing the while loop to while (!isset($_SESSION['var']) && $_SESSION['var'] !== true) , but I'm not sure that $_SESSION variable refreshes without reloading the page. Hope that works.

Upvotes: 1

Related Questions