如何停止一个PHP脚本在后台运行 [英] How do I stop a PHP script running on the background
本文介绍了如何停止一个PHP脚本在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始了这一进程(time.php)
I started this process (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 = "xxxxxxxxx@gmail.com";
$subject = "Hello Richie";
$header = "From: me@xxxxxxxxx.org";
$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的A / C。这就是我不能重新启动它杀死进程的Web服务器上。
but I now want to stop it. It's sending hundreds of mail to my Gmail a/c. It's on a web server where I cant restart it to kill the process.
有没有执行其他文件杀死进程的一种方式,或者我怎么去?
Is there a way to execute another file to kill the process, or how do I go about?
推荐答案
如果你没有shell访问,那么唯一的办法就是要求服务器administrater杀死进程。
If you don't have shell access, then the only way is to ask the server administrater to kill the process.
话虽这么说,没有建立一个脚本,使它能够在同一台服务器上的任何其他脚本被取消的简单方法如下:
That being said, there is an easy way to set up a script and enable it to be canceled from any other script on the same server, as follows:
<?php
// at start of script, create a cancelation file
file_put_contents('/tmp/myscriptcancelfile','run');
// inside the script loop, for each iteration, check the file
if ( file_get_contents('/tmp/myscriptcancelfile') != 'run' ) {
exit('Script was canceled') ;
}
// from any other script on the same server you can cancel the loop/exit with:
file_put_contents('/tmp/myscriptcancelfile','stop');
?>
这篇关于如何停止一个PHP脚本在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文