Cron Job in codeigniter - codeigniter

I want to create and use cron job . But i want it to be done by my script in codeigniter.
So is it possible to add a cronjob for a perticualr time when my conrtoller function is completed ?
If so please help...
Thank you

Sure you can!
You can execute any controller/action in codeigniter on command line this way:
php index.php controller_name action_name
So you can point a cron job on this particular route and execute anything that don't depends on browser (like sessions/cookies) into your job.
More info: http://www.codeigniter.com/user_guide/general/cli.html

You can use curl in cron jobs to execute or run the codeigniter in cron jobs
* * * * * /usr/bin/curl https://www.domain.com/controller/function

Related

Laravel not executing scheduled command

I'm using laravel telescope. I used the following code to schedule the prune command in kernel.php (it has 48 hours but I already tried with less hours):
$schedule->command('telescope:prune --hours=48')->daily();
I tested it in my local environment and it prunes the data correctly. But once in my production server it doesn't seem to be working.
Telescope is runing there and capturing data. I thought it could be a telescope command issue, but I ran
php artisan telescope:prune
and it works, it says "25404 entries pruned", I also verified this in the DB. Also, my cron task is runing every minute, and I have some scheduled calls like this:
$schedule->call('*some irrelevant stuff*')->cron('0 */3 * * *');
$schedule->call('*some irrelevant stuff*')->dailyAt('00:00');
And they are working as expected. I also tried calling the scheduller manually inside a function:
Artisan::call('schedule:run');
and the schedule calls work, but "$schedule->command" does not.
So, I'm guessing that the problem is that somehow "$schedule->command" is not working. Do you have any idea or suggestion to fix this?
You should set Laravel Task Scheduler to your's servers crontab file, adding the following entry:
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1

Cron job of my custom command in Laravel 4.2

I know there is Laravel 5.* now but for many reasons I'm using Laravel 4.2
I have a custom command, and in the fire() method, I import a file and seed the information in my database, so my class is some like this
class SeedDataFile extends Command {
protected $name = 'import:file';
public function fire(){
$command = 'mongoimport --db things --collection users --type csv --file file.csv --headerline';
$result = exec($command, $output, $return);
}
}
I want the file that is seeding data, i.e. every 12 hours (considering the file every 12 hours is changing with new data), but as an user I don't want to type the command in my terminal:
php artisan import:file
..every 12 hours (I just want to upload the new file to my project).
So the cron job is where I do all the work, but I don't want to do this:
crontab -e
and edit the file
I want to setup the schedule of my command in one class o somewhere in the code, and automatically the custom command is running everyday until a determined date.
Is this possible? Or I have to configure the crontab file?
You could take a look at this package, description says that it does exactly what you want
https://github.com/Indatus/dispatcher
As is Laravel 4.2 does not offer this type of functionality. In fact you'll need to set up 1 cron job for this functionality no matter the version you're using.
Newer versions of Laravel do indeed provide this functionality, but they still require you to set up 1 cron job (scheduler on Windows) at highest frequency available for Laravel's command php artisan schedule:run.
If you want to have scheduling of your commands in your code (rather than cron file) you could replicate what newer versions of Laravel do.
1. you would create a "master" command, let's call it TaskSchedulerCommand and let's say it's signature is php artisan schedule.
2. you would create a cronjob at highest frequency on the TaskSchedulerCommand like this: * * * * * php /path/to/artisan schedule`
3. you would write all the scheduling logic of other commands within the TaskSchedulerCommmand

Cron doesn't work in Magento1.7

I use Magento for my shopping, and I want to give all logged-in users have 3% discount for all products, so I wrote a rule, but it only worked for two days and after two days I had to re-apply it again, my Cron setting in Magento admin is:
Generate Schedules Every: 60
Schedule Ahead for:10
Missed if Not Run Within:60
History Cleanup Every:120
Success History Lifetime:120
Failure History Lifetime:120
To solve this problem, I wrote a Cron job in DirectAdmin panel to call cron.sh file in root of Magento (cron.sh is a shell script file that call cron.php), but it did not work properly, please guide me to solve this problem.
Cron job setting in Directadmin panel is:
0 0 * * * /usr/local/bin/php /home/noorantel/domains/nooran.com/public_html/shopping/cron.sh >> /home/noorantel/domains/nooran.com/public_html/shopping/var/logfile.txt
So firstly the Magento cron should run with the following regularity.
*/5 * * * *
This will mean that it will run every 5 mins.
Secondly you seem to mix up what type the file is either you need to run the php version or the bash version but what you seem to be doing is trying to run the bash version with php. Try the following.
*/5 * * * * /bin/sh /absolute/path/to/magento/cron.sh
Or
*/5 * * * * /usr/local/bin/php /absolute/path/to/magento/cron.php

Laravel4 task to cron

I'm trying to create a cron using a task I made. The problem is I have no clue how to build the cron. My task name is meeting:close, and it's in my commands folder.
Can anyone help me to build the url to call this task every hour? I guess it will start with 0 * * * *
Thanks everyone!
To create a cronjob, you have to edit a file. It is pretty easy, run crontab -e to edit the cron file for the current user.
Now just add a line to the file that opens:
0 * * * * php /full/path/to/your/application/artisan meeting:close
Maybe you also have to specify the absolute path to your php executable
Now save the file and you're all set.
By the way, if you didn't know, you can run your commands with php artisan command:name from the terminal (that's also what the cronjob is going to do...)

Status of cron job

I have written a cron job as follows:
$crontab -e
Then it opened a file where i wrote
5 * * * * USERNAME PATH-TO-SHELLSCRIPT
How would i come to know that my job has been executed?
Do something with the script? Edit a file and add timestamp for example to see if its ok :)
You can use a log file. Create a file under your home directory, e.g., "/home/user/.cronlog/script1", and output script execution time and status messages with timestamps. You can then check the logs to see script history. To test your script first execute it every minute. Then change the crontab entry to the actual period.
Also make sure you understand the time parameters so you know when to expect it to work :)
I use crontab for a 5 min interval cron like this: */5 * * * *
http://en.wikipedia.org/wiki/Cron

Resources