Welcome Guest, Not a member yet? Register   Sign In
Running CI Scripts from command line - Possible solution
#1

[eluser]fry-guy[/eluser]
While developing a newsletter script, I came across a solution to run my mailing script through the command line. Here's what I did:

1. Create a script called mailer.php in the main folder (where index.php is located)
/mailer.php - with the following content

Code:
// Mailer.php
ini_set("max_execution_time","0");
set_time_limit(0);

$mailingid = file_get_contents("data/mailing.txt");

$_SERVER['QUERY_STRING'] = '/sendmail/send/'.$mailingid;

include "index.php";

the mailing.txt file contains variable that needs to be passed to the mailing script.
Then run the script through the command line:

~]$php mailer.php

It works perfectly well for me, but I am not using mod_rewrite on this particular application and I have not tested it with mod_rewrite enabled. I will do that sometime this week and post the result here.

I hope someone will find this useful. :-)
#2

[eluser]gtech[/eluser]
thanks for that, that will be very useful to me.
#3

[eluser]Grahack[/eluser]
There are some other tricks like that in the wiki:
models from outside script
CI cron
use CI in other frameworks/apps
#4

[eluser]yongkhun[/eluser]
fry-guy's way not working for me. It just keep giving me Page Not Found error...
#5

[eluser]fry-guy[/eluser]
[quote author="yongkhun" date="1199464515"]fry-guy's way not working for me. It just keep giving me Page Not Found error...[/quote]

Are you using mod rewrite? If you are, then try this

Code:
ini_set("max_execution_time","0");
set_time_limit(0);

$_SERVER['QUERY_STRING'] = $argv[1];

include "index.php";

Save this file (e.g. cron.php) in your root codeigniter folder (where index.php is located)

and then run throught the command line:

Code:
$ php cron.php controller/function

Hope this helps
#6

[eluser]Peter Ivanov[/eluser]
Hello,

if you want to run CI scripts from the command line

why don't you use:


Code:
curl http://url_to_script/test.php




Theme © iAndrew 2016 - Forum software by © MyBB