Start/Stop Minecraft Server with PHP

浪尽此生 提交于 2019-12-11 22:37:26

问题


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:


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)



来源:https://stackoverflow.com/questions/25963868/start-stop-minecraft-server-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!