我开始这个过程(time.php)
<?php
ignore_user_abort(true); // run script in background
set_time_limit(0); // run script forever
$interval = 300; // do every 1 minute...
do
{
// add the script that has to be ran every 1 minute here
// ...
$to = "[email protected] /cdn-cgi/l/email-protection";
$subject = "Hello Richie";
$header = "From: [email protected] /cdn-cgi/l/email-protection";
$body = "Hello Richard,\n\n"
. "I was just testing this service\n\n "
. "Thanks! ";
mail($to, $subject, $body, $header);
sleep($interval); // wait 5 minutes
} while(true);
?>
但我现在想阻止它。它正在向我的 Gmail 账户发送数百封邮件。它位于网络服务器上,我无法重新启动它来终止该进程。
有没有办法执行另一个文件来终止进程,或者我该怎么做?
如果您没有 shell 访问权限,那么唯一的方法是要求服务器管理员终止该进程。
话虽这么说,有一种简单的方法可以设置脚本并使其能够从同一服务器上的任何其他脚本中取消,如下所示:
<?php
// at start of script, create a cancelation file
file_put_contents(sys_get_temp_dir().'/myscriptcancelfile','run');
// inside the script loop, for each iteration, check the file
if ( file_get_contents(sys_get_temp_dir().'/myscriptcancelfile') != 'run' ) {
exit('Script was canceled') ;
}
// optional cleanup/remove file after the completion of the loop
unlink(sys_get_temp_dir().'/myscriptcancelfile');
// To cancel/exit the loop from any other script on the same server
file_put_contents(sys_get_temp_dir().'/myscriptcancelfile','stop');
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)