Learning Blog

預定調和

Auto Restart Php Script by Register_shutdown_function and Pcntl_exec

| Comments

在使用PHP CLI 跑背景程式有時候會因為記憶體溢出或是其他原因導致程式停止執行,需要讓程式自行重新啟動。

register_shutdown_function 是可以讓PHP在意外終止的時候可以去執行特定函式,配合 pcntl_exec() 便可以 完成當程式發生FatalError 時可以自動重新啟動。

Comments