codeigniter
Creazione di cronjob in codeigniter su linux hosting server
Ricerca…
Chiamando un controller CodeIgniter da cron
// application/controllers/Company_controller.php
<?php
if(!defined('BASEPATH'))
exit('No direct script access allowed');
class Company_controller extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('companies_model');
}
// cron entry would be something like this:
// 1 1 * * * /usr/bin/php [full path to]/index.php company_controller cronCLI AcmeCorp >/dev/null 2>&1
public function cronCLI($firmName) {
if(php_sapi_name() == 'cli') {
$this->companies_model->doSomeDB_Process($firmName);
} else {
echo 'CLI only';
}
}
}
Cronjob in Codeigniter
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cron extends CI_Controller
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->library('input');
$this->load->model('cron_model');
}
/**
* This function is used to update the age of users automatically
* This function is called by cron job once in a day at midnight 00:00
*/
public function updateAge()
{
// is_cli_request() is provided by default input library of codeigniter
if($this->input->is_cli_request())
{
$this->cron_model->updateAge();
}
else
{
echo "You dont have access";
}
}
}
?>
Chiamalo dal tuo cpanel / cron manager come segue (ho aggiunto altri modi per chiamarlo):
0 0 0 0 0 php-cli /home/your_site_user/public_html/index.php cron updateAge
O
0 0 0 0 0 wget http://your_site_url/cron/updateAge
O
0 0 0 0 0 /usr/bin/php /home/your_site_user/public_html/index.php cron updateAge
Nel mio caso: wget thing sta lavorando su plesk e cpanel (wget crea file sul server nella tua directory root). php-cli funziona su plesk e cpanel entrambi.
Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow