Start/Stop Minecraft Server with PHP

2019-09-02 16:14发布

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.

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")

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)

1条回答
Root(大扎)
2楼-- · 2019-09-02 16:47

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")

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")

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

查看更多
登录 后发表回答