使用PHP启动/停止Minecraft服务器 [英] Start/Stop Minecraft Server with PHP

查看:484
本文介绍了使用PHP启动/停止Minecraft服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的10个小时里,我一直试图找到一种方法来启动/停止与我的php脚本位于同一目录中的craftbukkit.jar文件。我已经尝试了几乎所有我在stackoverflow上找到的解决方案,但没有一个能够工作。

For the last 10 hours I have been trying to find a way to start/stop a craftbukkit.jar file that is in the same directory as my php script. I have tried nearly all of the solutions I could find on stackoverflow and none of them worked.

我试过两个 shell_exec(java -Xms1024M - Xmx1024M -jar craftbukkit.jar -o true); exec(java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true); 我还尝试将 java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true 放在外部的start.sh文件中,然后用 exec(start.sh)

I tried both shell_exec("java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true"); and exec("java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true"); I also tried putting the java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true in a external start.sh file and then running it with exec("start.sh")

我做错了什么?它应该在进程运行时创建所有bukkit配置文件(就像在计算机上运行它时一样)

What am I doing wrong? It is supposed to create all of the bukkit configuration files when the process is ran (just like it would when you run it on your computer)

推荐答案

我认为你需要一个控制台来运行服务器...
i会推荐服务器的屏幕会话:

I think you need a console to run the server in... i would reccomend a screen session for the server:

启动服务器该命令可能如下所示:

To start the server the command could look like this:

exec("screen -S bukkit sh /home/user/bukkit/start.sh")

-S选项用于命名会话。
所以当你想通过ssh连接到控制台时,你只需要做

the -S option is to name the session. so when you want to connect to the console through ssh for example you simply do

screen -r bukkit

也许你应该使用命令的绝对路径...如果它更好或不更好

maybe you should use absolute paths for the command... not shure if its better or not

有一种方法可以向该会话发送一些命令来停止服务器...但我现在不记得了!

there is a way to send some commands to that session to stop the server as well... but i dont remember right now!

如果你不使用屏幕,你可以尝试

if you do not use screen for smth else you could try

exec("killall screen")

杀死所有的屏幕搜索...
但要小心,因为服务器可能无法保存最近的更改(没有关闭bukkit-server)

to kill all screensessions... but be careful with that because the server might not save recent changes(no shutdown of the bukkit-server)

这篇关于使用PHP启动/停止Minecraft服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆