Loading...

php定時執行任務ignore_user_abort() 函式

Temperature: 0 °C

Mark ChangMark Chang
author_tools

ignore_user_abort() 函式

PHP 4, PHP 5, PHP 7

最近剛好有一個專案需要定時執行任務功能,原本一開始想到的是在伺服器上設定時間排程。

但由於網站空間的設定權限並不一定可以拿到,所以Google了一下關於php方面執行定時任務的方式資訊。

剛好看到了ignore_user_abort() 函式。並通過以下設定來達到我要的定時執行任務功能:
ignore_user_abort();//關掉瀏覽器,PHP腳本也可以繼續執行。
set_time_limit(0);// 通過set_time_limit(0)可以讓程序無限制的執行下去。
$interval=60;// 每隔60秒運行。

然後透過死循環方式
do{
//這邊置入想要執行的任務
sleep($interval);// 等待60秒
}while(true);

但由於這種方式很耗系統資源,所以建議僅使用於簡單任務。
Url link
以上紀錄
 

https://innstory.com/story-php定時執行任務ignoreuserabort_函式-2055
PHP

Prev
 在PHP中通過POST發送JSON

Next
WordPress如何關閉迴響留言功能 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

當域名 DNS 尚未生效時,如何預先設定及測試網站

當域名 DNS 尚未生效時,...

建置一個新的網站或是將網站搬家時 常常會遇到一個問題,就是要將網址指向到新的網站空間,設定完畢但需要...

PDO bindParam 和 bindValue 差別在哪裡?

PDO bindParam ...

首先 bindParam 是綁定變數、bindValue  是綁定值。 以下範例: bindPara...

Format JavaScript Date to yyyy-mm-dd

Format JavaScr...

timecalendar5 JavaScript將Sun May ,轉換成yyyymmdd func...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format