Issue
I have a PHP file that checks if a field in MySQL database is empty. If the field is empty, PHP is an update. I want to color this file in the background on Linux. If a user creates a record, the PHP file in the background will be updated. My PHP code:
<?php
$mysqli = mysqli_connect("localhost","name","pass","database");
$query = 'UPDATE users SET permissions = "content" WHERE permissions = ""';
$n = $mysqli->query($query);
$query = "SELECT * from users";
$result = $mysqli->query($query);
$row = $result->fetch_array(MYSQLI_ASSOC);
$subdominio = $row["name"];
$created_at = $row["created_at"];
?>
How can I do this? I can have problem with it file PHP in the background on Linux? Performance, slow down and etc?
Thanks very much!
Solution
- Create PHP file and put your code there. (For example myfile.php)
- Install '
screen
' :
Ubuntu & Debian: apt-get -y install screen
CentOS & Fedora: yum -y install screen
**** Follow steps 3 & 4 to execute myfile.php all the time. And follow steps 5 & 6 to execute myfile.php every 1 minute or every X time using crontab. ****
- Type '
screen
' . Type '
php myfile.php
' . And minimize/hide it by pressingCtrl + A + D
. And get back to it by typing 'screen -r
' .Type '
crontab -e
' .- To execute every minute, you can type '
* * * * * php myfile.php
' ... If you don't want every minute, Google about crontab.
Answered By - protld Answer Checked By - Willingham (WPSolving Volunteer)