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

使用.htaccess關閉特定文件的緩存

使用.htaccess關閉特...

以特定檔案為例 <Files page.php> FileETag None Header unse...

MySQL:ERROR_1067

MySQL:ERROR_10...

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

php使用PDO獲取結果的方法

php使用PDO獲取結果的方...

fetch() 式例如下: mixed PDOStatement::fetch([int fetch...

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