2011-06-08 100 views
1

我有一個腳本,插入到數據庫中,例如20,000郵箱地址的用戶批量爲1000代碼點燃器和exec?

(so two tables,emailParent,emailChild),emailParent中的每一行在emailChild中有1000行。

我想運行發送這些郵件,基本上說,現在 //check_for_pending_parent_rows() returns the id of the first pending row found, or 0
while($parentId = check_for_pending_parent_row()){//loop over children of parent row}

因爲這是談話的sendgrid服務器這可能需要一些時間的腳本。

所以我希望能夠打一個頁面,讓那個頁面啓動一個後臺進程,發送郵件到sendgrid。

我以爲我可以使用exec()但後來我意識到,我使用的代碼點火器,這意味着入口點必須是index.php因此,我不認爲exec()會的工作,

我如何可以啓動一個後臺使用代碼點火器的過程?

+1

你可以通過'index.php'和'system/codeigniter/CodeIgniter.php'的一部分來構建一個腳本來完成基本的CI初始化。這不是很漂亮 - 我看到的代碼大約有70行(格式化,評論)PHP。我沒有權限分享我正在查看的代碼,但它爲類似問題引用了更強大的解決方案:http://www.foostack.com/foostack/ – 2011-06-08 02:14:23

回答

1

使用exec通過cURL

運行香草CLI PHP腳本調用的頁面見http://php.net/manual/en/book.curl.php的信息上捲曲

這是我曾與一些做我的codeigniter應用程序

(還請確保您將超時設置爲0)

而且做這種方式,你仍然能夠調試在瀏覽器

2

這是不是一個真正的答案,只是一些太長張貼作爲評論

@Frank農民:70行似乎有點簡單 測試做它 過度,這個例子在幾乎一半, 有什麼區別?

<?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 
1

佩塔提克瓦建議捲曲,但最近(自2.0),笨現在允許通過CLI調用你的控制器:

這應該比cURL更容易。