开发者

code igniter and exec?

I have a script that, inserts into the database e.g. 20,000 users with email addresses in batches of 1000

(so two tables, emailParent, emailChild), there are 1000 rows in emailChild for every row in emailParent.

I want to run a script that sends these emails which basically says //check_for_pending_parent_rows() returns the id of the fi开发者_JS百科rst pending row found, or 0

while($parentId = check_for_pending_parent_row()){//loop over children of parent row}

Now because this is talking to the sendgrid servers this can take some time.

So I want to be able to hit a page and have that page launch a background process which sends the emails to sendgrid.

I thought I could use exec() but then I realized, I am using code igniter, which means the entry point MUST be index.php hence, I don't think exec() will work,

How can I launch a background process that uses code igniter?


This is not really an answer, Just something that is too long to post as a comment

@Frank Farmer: 70 lines seems a bit excessive, this example from simple test does it in pretty much half that, What is the difference?

<?php
//---------------------------
//define required constants
//---------------------------

define('ROOT', dirname(__file__) . '/');
define('APPLICATION', ROOT . 'application/');
define('APPINDEX', ROOT . 'index.php');

//---------------------------
//check if required paths are valid
//---------------------------
$global_array = array(
    "ROOT" => ROOT,
    "APPLICATION" => APPLICATION,
    "APPINDEX" => APPINDEX);

foreach ($global_array as $global_name => $dir_check):
    if (!file_exists($dir_check)) {
        echo "Cannot Find " . $global_name . " File / Directory: " . $dir_check;
        exit;
    }
endforeach;

//---------------------------
//load in code igniter
//---------------------------
//Capture CodeIgniter output, discard and load system into $ci variable
ob_start();
include (APPINDEX);
$ci = &get_instance();
ob_end_clean();

//do stuff here


Use exec to run a vanilla CLI PHP script to calls the page via cURL

See http://php.net/manual/en/book.curl.php for info on cURL

This is what I have had to do with some of my codeigniter applications

(Also make sure you set time out to 0)

And doing it this way, you are still able to debug it in the browser


Petah suggested cURL, but recently (since 2.0), CodeIgniter now permits calls to your controllers through the CLI:

This should be easier than cURL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜