Background: I’m running a Minecraft server for friends on a VPS, and I’m attempting to create a sort of “status webpage” for it, using PHP. This is the last thing I have tried to implement; I have a server up/down indicator, online time, etc.
The script I’m having trouble with is displaying a player list. Ideally, what I want to be able to do is display a list of the names of people that play on my server, colour grey the people who are offline, and blue those who are online.
Now the part I’m having an issue with:
the minecraft server jarfile is executed in a ‘screen’, labelled minecraft. To obtain the listof online players, I should be able to execute (in the screen) ‘list’, followed by enter, and it spits out a list of players.
I tried many different ways of executing the command in the screen from PHP, such as:
$online = shell_exec('screen -S minecraft -X print "list\r"');
echo "<pre>Players online: $online";
The result always echoed on the webpage is
Players online: No screen session found.
What am I doing wrong? MY php is abysmal (I have never learnt PHP and am learning straight off the reference), but this seems straightforward?
On a side note, what’s the best way to achieve a dynamic highlighted list of characters? An array of characters that play, and explode() and compare, or should I be writing to databases and comparing from that?
Thanks in advance everyone.
PS: for reference, website is located at http://fudgesminecraftserver.info, and you can see what’s happening right there.
This is most likely a Linux permissions issue. You need to give the user running Apache (www-data ?) permission to execute command ‘screen’