Welcome Guest, Not a member yet? Register   Sign In
Send a mail through cron jobs using a controller
#1

[eluser]andrewpraveen[/eluser]
Hi,

Andrew here, I just completed my website and now i m having a requirement to sent a every min mail to customer who have pending orders, suppliers who have pending orders, and admin will receive a status as well.

I used to execute the below code for cron jobs.

Code:
wget --delete-after http://travablue.com/cron_jobs/jobs/

in the cpanel.

but above code is using the http, therefore my server is getting delay for some time to response. therefore I tried to find a solution and got about CI method.

therefore i gone through with all the blogs and forums and got the code as;

Code:
php /home/andrew/public_html/index.php cron_jobs jobs

when i call a test.php in the public_html folder, it works, but this cron_jobs is a folder in the controller, and jobs is the controller as well. in the index function I m calling a model function as well which has the query and mail function. here the below is the controller file code;

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jobs extends CI_Controller {

function __construct()
{
  parent::__construct();  
  $this->load->model('cron_job_model');
  $this->input->is_cli_request();
}

public function index()
{
  $this->cron_job_model->local_agent_cjob_every_min();
  $this->cron_job_model->tm_jobs_agent_not_response();
  
}
}

but here in the cpanel i set up my email add to check the execution as well. I got the mails as below;
Quote:Status: 301 Moved Permanently
X-Powered-By: PHP/5.4.24
Set-Cookie: ci_session=a:5:{s:10:"session_id";s:32:"c789186862470db1cda96739c08f7427";s:10:"ip_address";s:7:"0.0.0.0";s:10:"user_agent";b:0;s:13:"last_activity";i:1409979002;s:9:"user_data";s:0:"";}698581f4c581ff20f6b4e1d16e7d4c02; expires=Sat, 06-Sep-2014 11:20:02 GMT; path=/
Location: http://travablue.com/en
Content-type: text/html

I m not sure where i m having the issue. In the code, or in the cron job ci calling command or in the .htaccess. Anyway i m giving the .htaccess file also.

Code:
DirectoryIndex index.php
RewriteEngine on
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

Any experts please let me know the fix... I m really need it as soon as possible.
#2

[eluser]InsiteFX[/eluser]
Try this:
Code:
php /home/andrew/public_html/index.php/cron_jobs/jobs
#3

[eluser]andrewpraveen[/eluser]
I got the alert mail saying!

Status: 404 Not Found
X-Powered-By: PHP/5.4.24
Content-type: text/html

No input file specified.
#4

[eluser]andrewpraveen[/eluser]
[quote author="andrewpraveen" date="1410057430"]I got the alert mail saying!

Quote:Status: 404 Not Found
X-Powered-By: PHP/5.4.24
Content-type: text/html

No input file specified.
[/quote]
#5

[eluser]InsiteFX[/eluser]
Maybe this will help you:

CodeIgniter Setting up Corn Jobs
#6

[eluser]andrewpraveen[/eluser]
Any way I use the CURL method to do the job. but thanks for the help. I will try again this link. if it works definitly i will post you back .... thanks again.
#7

[eluser]andrewpraveen[/eluser]
I used below command to do the job. Works fine.

Code:
php-cli /home/devtrava/public_html/index.php cron_jobs jobstest index

All the best guys.

I'm posting this experience in my blog too as tutorial. Lets check it up guys.

http://apnlab.blogspot.com/




Theme © iAndrew 2016 - Forum software by © MyBB