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

MySQL:ERROR_1067

MySQL:ERROR_10...

最近安裝了Ubuntu Server .系統。 接著安裝了MySQL 5..的版本。 在時間的預設值...

使用PHP取得目前網址方式

使用PHP取得目前網址方式

pexelsphoto55 使用PHP取得網址相關的方式有下列幾種: $SERVER["R...

使用 Closure Compiler 幫 javascript 瘦身

使用 Closure Com...

JavaScript(縮寫為JS)是一種進階的、直譯的程式語言,且作為客戶端手稿語言在使用者的瀏覽器...

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