2

I am using codeigniter to create some cronjobs I scheduled it using Task schedular in windows 7. It runs every one minute but what i see is it just popup my code in an editor and does not insert any data in my database that I mentioned in index function.

<?php
class Hello extends CI_Controller {
 public function __construct() {
    parent::__construct();
    $this->load->database();
}

public function index() {
     $this->db->query("INSERT INTO test_cron VALUES(null, 'username')");
}
}
?> 

How can I really execute it so That it insert data in my database

Thanks

9
  • Are you using CPanel? If so checkout this image, you just have to find the cronjob area on your panel. If you're using a linux server without control panel checkout this url, if you are using windows or need any other help let me know and I'll post a guide. Apr 27, 2012 at 13:05
  • @Whiteagle I am using windows 7 Apr 27, 2012 at 13:06
  • Is windows 7 your production or development environment? Apr 27, 2012 at 13:07
  • Refer to this question. Apr 27, 2012 at 13:09
  • 2
    Oh, you're on Windows. You can forget about cron and that tutorial then. Try to use Windows Scheduler or something.
    – Mischa
    Apr 27, 2012 at 13:10

3 Answers 3

2

IF YOU ARE USING *.NIX:

*nix command:

crontab -e -u USERNAME

If you wanna edit with nano:

env EDITOR=nano crontab -e -u USERNAME where username is the user which will initiate the script.

If you wanna run it hourly:

01 * * * * ...

For Windows 7, as you asked: Start => Accessories => System Tools => Task Scheduler

  • Create task
  • Actions
  • New
  • choose the path to script and don't forget to add php before script, in order to execute, not just open.

To run script with a specified period or by date, use Triggers tab.

And there configure the task to run you're PHP script.

12
  • Is it possible to run a codeigniter controller by scheduling a task? Apr 27, 2012 at 13:30
  • Yes, cause in the end running a codeigniter controller is calling script. I've done it for Symfony, say for cron controller, I've just configured task to run cron.php, and in routing defined my homepage for this controller as pointing on cron action.
    – devdRew
    Apr 27, 2012 at 13:33
  • There is no option to run the script after every minute or hour. Apr 27, 2012 at 13:34
  • Yes I found it now I run it every one minute it is running but the quesry is not working... should I edit my question and provide you the code which I want to run ? Apr 27, 2012 at 13:40
  • What do you mean saying query is not running...? Try to improve your code with logging, and if there were errors, - log it, and debug.
    – devdRew
    Apr 27, 2012 at 13:44
1

crontab is a linux program and you say that you are using windows 7; in windows you will have to try a similar thing with scheduled tasks

(that syntax is only for unix)

2
  • Ny idea about how o run it on windows? Apr 27, 2012 at 13:14
  • 1
    @FaryalKhan you should google about using windows scheduled tasks; most people here are used to running the applications on unix operating systems; if you say that you are using win 7 you should be able to find what you need if you open the start menu and just type "task scheduler".. you will find a program that allows you to set up "cronjobs" using a GUI.. and your script will run using the full path to the php exe and the path to the script as a parameter
    – mishu
    Apr 27, 2012 at 13:19
0

On your server, you use the command crontab -e, which will open an editor for you where you add the code to your crontab. To have it run every hour, change the line to:

00 * * * * /usr/local/bin/php5 $HOME/system/scripts/clean_cache.php

More details about the crontab format.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.