How to setup cronjob in local XAMPP (with task scheduler) in codeigniter3

edited January 25 in PHP

1)  Create a batch file that will execute the CodeIgniter controller or script you want to run as a cron job. Open a text editor (like Notepad) and create a new file. Save it with a .bat extension, for example, runcronjob.bat . Include the code below given in your .bat file .

2) Write the logic you want to handle in your controller (your_controller)

3) Schedule a Task in your system by following these steps:

1. Press Win + S, type "Task Scheduler," and open it.

2. In the Actions pane, click on "Create Basic Task."

3. Follow the wizard to set a name and description for your task.

4. Choose the trigger based on your schedule (daily, weekly, etc.).

5. Select "Start a Program" as the action.

6. Browse and select the batch file you created (runcronjob.bat) as the program/script.

7. Complete the wizard and click "Finish."


CODE:

// .bat file code
@echo off

cd C:\xampp\htdocs\your_codeigniter_project_folder

php C:\xampp\htdocs\your_codeigniter_project_folder\index.php  your_controller your_method

//Handle your code in your_controller 

public function your_method

{
    //your logic
}


4) Now, your cron job is scheduled to run at the specified intervals.

Note: Make Sure that your XAMPP Server is running at the time of your task is scheduled to be performed

Tagged:
Sign In or Register to comment.