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

Android Fragment及Activity 中使用sharedpreferences

Android Fragme...

在Android下想要儲存執行資料的方式有好幾種,例如存在手機空間或者是資料庫空間。 這裡紀錄一下使...

PHP清空陣列函數

PHP清空陣列函數

pexelsphoto5555 unset(arrar) 將整個陣列清空,但之後如果再加入元素,其 ...

使用CSS 讓ul li 橫向水平

使用CSS 讓ul li 橫...

好吧,其實這個css常在用,但我每次都沒特別紀錄,然後每次又忘記然後又要Google。 其實主要就是...

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