【发布时间】:2015-06-16 23:56:49
【问题描述】:
我试图找到一种方法来关闭我最近用 PHP 打开的程序。启动和停止服务器系统的一部分(使用 .bat 用 java 制作的服务器)。我只能让它在后台打开,是的,我启用了与桌面的交互。我想知道是否有一种方法可以返回我最初启动的程序进程的 PID,然后使用该 pid 稍后关闭程序。
开始的 PHP 页面代码
<?php
session_start();
$id = $_GET['serverid'];
$mysqli = new mysqli("localhost", "root", "", "mainrspshosts");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT * FROM servers WHERE id = '" .$id. "' LIMIT 1";
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
if($_SESSION["username"]==$row["owner"]){
set_time_limit(300);
echo "Starting...<br><br>";
$output = shell_exec('c:\WINDOWS\system32\cmd.exe /c START run474.bat');
echo($output);
echo "Success!";
header("refresh:5;url=http://rspshost.zapto.org/ucp/serverstartedvalidation.php");
}
else{
header("location:index.php");
}
}
}
else{
header("location:index.php");
}
?>
【问题讨论】: