mardi 24 mars 2015

Run PHP when a variable changes


Vote count:

0




I have an issue with my php code. I want to add something into my database when a variable changes. I'm getting a variable from another file that changes.


below you can find the code:



$urlMachineON = 'http://ift.tt/1GbRIuI';

// get content
$contentMachineON = file_get_contents($urlMachineON);

//remove first 2 characters
$truncate = substr($contentMachineON, 2);

//remove last 5 characters
$MachineOn = substr($truncate, 0, -5);

if ($MachineOn == 0)
{
echo "de machine staat uit";
//Send information to the database
//example: current time + MachineStatus(off) + message(Machine offline Error X)
}
elseif($MachineOn == 1)
{
echo "de machine staat aan";
//Send information to the database
//example: current time + MachineStatus(on) + message(Error X is solved)
}


When I do it like this it will only set information in my database when I refresh my webpage or use some kind of button. But it kinda has to go automatic. So when the variable $MachineOn goes from 0 to 1 or 1 to 0 it has to add information in my database. How can I solve this?



asked 1 min ago

Bart

31






Run PHP when a variable changes

Aucun commentaire:

Enregistrer un commentaire