我现在有一百多个 php 脚本在我的服务器上运行。他们每个人都运行循环并将数据插入我的数据库。我这样做是为了学习在 mysql 中终止进程。因此,为了杀死它们,我编写了一个 php 文件,该文件循环遍历进程列表并一个接一个地杀死它们。问题是这个脚本没有被执行。它一直在我的浏览器中加载(没有错误...)。另请注意,我无法在 mysql 中手动启动 show processlist,因为 mysql 目前完全重载,没有任何响应。所以我猜我的“杀死进程”脚本是队列中的最后一个,只会在最后执行。所以我的问题是知道是否有办法在 mysql 中强制一个进程并将其置于第一优先级。预先感谢您的答复。干杯。马克
这就是我终止进程的方式:
$qry = mysql_query("SHOW FULL PROCESSLIST");
while ($row=mysql_fetch_array($qry)) {
$process_id=$row["Id"];
$sql="KILL $process_id";
mysql_query($sql);
}
最佳答案
我不确定这是否真的会影响 MySQL,但在 Unix/Linux 上,您可以尝试调用 proc_nice()
在脚本的顶部附近有一个负增量(如 -20)。它基本上与 nice
command 做同样的事情。 .
"... nice is used to invoke a utility or shell script with a particular priority, thus giving the process more or less CPU time than other processes. A niceness of −20 is the highest priority and 19 or 20 is the lowest priority. The default niceness for processes is inherited from its parent process, usually 0."
关于PHP MySql - 如何确定进程的优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9807422/