PHP-CI - CLI

摘要:PHP-CI - CLI

為了排程,

看到這篇文章

http://codeigniter.org.tw/user_guide/general/cli.html

 

造著做,會發生前後會發生兩個錯誤。

Cannot modify header information - headers alerady sent by 
http://stackoverflow.com/questions/3395000/why-im-getting-cannot-modify-header-information-headers-already-sent-by-regist
 
在 index.php 開頭加入 on_start();
<?php
ob_start();
/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 
 
Undefined index: REMOTE_ADDR
http://stackoverflow.com/questions/18082618/php-error-encountered-when-running-command-line-using-codeigniter-2-xx
 
在/system/core/Input.php 351行 改成
$_SERVER['REMOTE_ADDR'] → $this->server('remote_addr')
 
這樣應該使用command line 時,應該就不會出問題了。
 
再將 command line 寫成 bat
再設定環境變數,讓php.exe位置能夠被直接找到
http://fellowtuts.com/php/run-php-from-command-line-in-windows-and-xampp/
然後再建立Windows 排程
http://twids.cute.edu.tw/parser/autowork
(1) Windows Vista / 7 環境: 請使用Windows [工作排程器]
     [開始] >>> [執行] >>> 輸入 taskschd.msc >>> [執行] >>> [建立基本工作] 
        >>> 請自訂名稱,設定每天執行  >>>  設定每日執行時間  >>>  設定 [啟動程式] >>>
        >>> 指定對應的 bat 批次執行檔  >>> 完成 。
 
就大功告成