Julio Mac Julio Mac - 1 year ago 77
Linux Question

Put php file in the background on Linux

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:

$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!

Answer Source
  1. Create PHP file and put your code there. (For example myfile.php)
  2. 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. ****

  1. Type ' screen ' .
  2. Type ' php myfile.php ' . And minimize/hide it by pressing Ctrl + A + D. And get back to it by typing ' screen -r ' .

  3. Type ' crontab -e ' .

  4. To execute every minute, you can type ' * * * * * php myfile.php ' ... If you don't want every minute, Google about crontab.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download