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

使用CSS讓Youtube自動適應寬度跟高度

使用CSS讓Youtube自...

pexelsphotomedia 在播放Youtube影音的時候,常使用 iframe 的方式崁入網...

錯誤訊息Division by zero的解決方式

錯誤訊息Division b...

錯誤訊息Division by zero發生的原因是因為除數是導致的錯誤: 解決方式如下: ) 運行...

要如何知道ajax執行失敗原因?

要如何知道ajax執行失敗原...

只要在error的function 更改為以下寫法即可: error: function (XMLH...

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