如何在PHP CodeIgniter中创建Cron作业

I need to run a query by using Cron job in CodeIgniter. How to create a Cron job with below mentioned details(weekly, 7 weeks, repeat on, and time). Here I attached the screenshot for your reference.

enter image description here

Please suggest around this.

Thanks in advance!

There is no build in cron function in codeigniter. What you can do is:

Create a cron on your server, which is calling a controller every x-time, e.g. every 5 minutes.

You create a new controller, e. g. scheduler, which is called by the server cron. In this controller you handle the cron request and checking the execution time.

The only difficult part is to calculate the times from a user input.

A not well written but working PHP solution is here: PHPScheduler

It is not codeigniter, but you can use this as a starter.

Trigger a cron job.

  • You should write a function in controller to do what you required(sending notifications / anything you want to do there.).
  • You should make sure that, you controller funtion doesn't have any session related to it.

I have added following images , refer them

enter image description here

I have added a cron which runs once in a day. and in your server, it looks like this.

enter image description here