crons job

 config.php

<?php

$servername = "localhost";

$username = "pakpoultrypk_website";

$password = "qhofB132";

$db = "pakpoultrypk_website";

// Create connection

$con = mysqli_connect($servername, $username, $password,$db);

// Check connection

if (!$con) {

  die("Connection failed: " . mysqli_connect_error());

}

echo "Connected successfully";

?>


mainfile.php

#!/usr/bin/php 

Or use this

#!/usr/bin/env php

<?php 

  require_once('config.php');

  $date = date('Y-m-d');

  mysqli_query($con,"DELETE FROM broiler WHERE expDate<='$date'");

  mysqli_query($con,"DELETE FROM chicksBroiler WHERE expDate<='$date'");

  mysqli_query($con,"DELETE FROM chicksDomestic WHERE expDate<='$date'");

  mysqli_query($con,"DELETE FROM domesticFarming WHERE expDate<='$date'");

  mysqli_query($con,"DELETE FROM eggDomestic WHERE expDate<='$date'");

  mysqli_query($con,"DELETE FROM eggLayer WHERE expDate<='$date'");

  mysqli_query($con,"DELETE FROM workers WHERE expDate<='$date'");

  mysqli_query($con,"DELETE FROM poultryFarm WHERE expDate<='$date'");

?>

path of the file

/home/pakpoultrypk/domains/pakpoultry.com.pk/public_html/crons/deleteExpads.php



for help read this

https://stackoverflow.com/questions/9498298/permission-denied-in-cron-jobs-command


22

Use php /home/gbtusyll/public_html/run.php instead to run it as a PHP script instead of a regular shell script.

  • 1
    Thnaks.For the first time i am using cronjob and it help me. – pkk Oct 7 '15 at 11:35
  • I am also new to cronjob. For new users, it should be noted that the link to your path to environment should also be properly mentioned in most cPanels like this /usr/local/bin/php, instead of just php. So use /usr/local/bin/php /home/cPaneluser/public_html/yourscript.php. Some cPanels with shared hosts may have different paths. /usr/local/bin and /usr/bin are popular paths from root. (Apparently, godaddy uses both, based on case. (1) (2) ) – Siddhant Rimal Apr 23 '17 at 1:20 
  • Thanks. Its working fine. This might be checked as correct answer. – Niby Aug 2 '18 at 6:11 

Comments

Popular posts from this blog

Laravel 8 Multi Auth (Authentication) Tutorial

MySQL - Stored Procedures && Functions