Welcome Guest, Not a member yet? Register   Sign In
Setting up overnight email script
#1

[eluser]acesfull9[/eluser]
So I want to make a script that runs overnight and sends emails for my codeigniter application. I was wondering what is the best way to approach this while being able to take advantage of the code igniter libraries that may be useful.
1. I could write it as a controller and just request the url of that controller every night.
With that, I am not sure about request timing out or someone accessing the controller who is not the overnight batch job.

Is there anyway to call a codeigniter controller or some other class from the command line. Any suggestions of the best way to approach this would be greatly appreciated, thanks!
#2

[eluser]James Gifford[/eluser]
You can create a script which will call a CI controller from the crontab and run the code without using your webserver.

Here is how I handle this:

1. Make a new folder in your application directory for storing CLI scripts.
2. Copy the index page in your web root to a new file in your scripts folder (we'll call it script.php).
3. Add a line like this at the top of script.php:
Code:
$_SERVER['PATH_INFO'] = '/controller_name/method_name';
4. Change the system_folder and application_folder variables to point to the corresponding folders from the filesystem root. Because the script will be running without the webserver, you have to reference everything from the file root, not the web root. In my case this looks something like this:
Code:
$system_folder = "/Library/WebServer/system";
$application_folder = "/Library/WebServer/my_application";
5. Add an entry in your crontab for this script and schedule it to run when desired.
#3

[eluser]acesfull9[/eluser]
Thank you!




Theme © iAndrew 2016 - Forum software by © MyBB