无法在 Linux 的“屏幕”中执行命令;来自 PHP 脚本
背景:我正在 VPS 上为朋友运行 Minecraft 服务器,并尝试使用 PHP 为其创建一种“状态网页”。这是我尝试实现的最后一件事;我有一个服务器启动/关闭指示器、在线时间等。
我遇到问题的脚本是显示玩家列表。理想情况下,我想要做的是显示在我的服务器上玩的人的姓名列表,将离线的人设置为灰色,将在线的人设置为蓝色。
现在我遇到的问题是:
minecraft 服务器 jar 文件在标记为“minecraft”的“屏幕”中执行。要获取在线玩家列表,我应该能够(在屏幕中)执行“list”,然后按 Enter 键,然后它会输出玩家列表。
我尝试了许多不同的方式从 PHP 在屏幕上执行命令,例如:
$online = shell_exec('screen -S minecraft -X print "list\r"');
echo "<pre>Players online: $online";
网页上总是回显的结果是
Players online: No screen session found.
我做错了什么?我的 php 很糟糕(我从来没有学过 PHP,而是直接从参考资料中学习),但这看起来很简单?
顺便说一句,实现动态突出显示字符列表的最佳方法是什么?播放的字符数组,爆炸()并进行比较,或者我应该写入数据库并从中进行比较?
预先感谢大家。
PS:作为参考,网站位于 http://fudgesminecraftserver.info,您可以在那里看到发生了什么。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很可能是 Linux 权限问题。您需要授予运行 Apache (www-data ?) 的用户执行命令“screen”的权限
This is most likely a Linux permissions issue. You need to give the user running Apache (www-data ?) permission to execute command 'screen'