Php 关机前执行一个函数
触发断电时如何执行功能Php 关机前执行一个函数,php,linux,Php,Linux,触发断电时如何执行功能 // need to make sure here that poweroff command is executed successfully before calling senEmail function $output = exec('poweroff', $output, $return); if (!$return) { // command executed successfully // now send email before powe
// need to make sure here that poweroff command is executed successfully before calling senEmail function
$output = exec('poweroff', $output, $return);
if (!$return) {
// command executed successfully
// now send email before poweroff completes its process
sendEmail();
}
sendmail()
不会触发,因为关机已在处理中。根据系统详细信息,poweroff
将调用,这可能更适合从程序调用<代码>关机可指示系统在一段时间后关闭
您可以发送邮件以响应SIGTERM信号,关机进程将发送该信号。在这方面有很多可用的资源。发送电子邮件所需的流程一直存在着失败的风险
更好的是,你可以改变依赖关系的顺序:在合理的宽限期内调用
shutdown
,尝试发送电子邮件,如果发送失败,取消关机。你不能。您可以在执行断电命令之前发送邮件。@Karthikeyan.R.S,Aw!那太可悲了,伙计。还有别的办法吗?嗯。。那是个好主意。谢谢你的洞察力。你很酷。谢谢