2009年1月15日星期四

利用 Wget + Crontab 定期執行 Web app

某些資料量大的網站會定期將龐大的資料表定期轉換成 summary table,此時可利用原本的 dynamic page 實作,並利用 linux 下的 wget + crontab 定期執行。

例如網站管理者希望每十分鐘自動執行 http://192.168.0.1 這台伺服器上的 refresh.php 這個網頁,則將在 crontab 下加入下列指令:

*/10 * * * * wget –q –O – http://192.168.0.1/refresh.php

===== 參數說明 =====

-q : quite 背景執行,不顯示結果

-O : output 輸出位置,後面加上 「-」表示不另外儲存

另外如果程式需要做參數傳遞的話,可以使用 Querystring (GET method),或是使用 wget 提供的 POST 字串傳值,如:

--post-data=STRING use the POST method; send STRING as the data.

--post-file=FILE use the POST method; send contents of FILE.

0 意見: