Faryal Khan
Faryal Khan

Reputation: 869

How to run PHP script with Windows Task Scheduler

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

Upvotes: 2

Views: 5234

Answers (3)

devdRew
devdRew

Reputation: 4581

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.

Upvotes: 2

cschorn
cschorn

Reputation: 1217

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.

Upvotes: 0

mishu
mishu

Reputation: 5397

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)

Upvotes: 1

Related Questions