使用 php 终止 GNU 屏幕会话
我在我的 VPS 上为我的伙伴托管了一个游戏服务器,我尝试为他制作一个网页,以便他在需要时停止服务器。
我正在使用的是:
system('/bin/sh stopserver.sh');
这是 stopserver.sh 中的内容:
/usr/bin/screen -S server -X但这
给我的只是这条消息:必须连接到终端。
有什么建议吗?
I'm hosting a gameserver for my mate on my VPS, and I tried to make a webpage for him to stop the server if he wants.
What I'm using is:
system('/bin/sh stopserver.sh');
this is what is inside stopserver.sh:
/usr/bin/screen -S server -X kill
but all this gives me is this message: Must be connected to a terminal.
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这可能是您正在使用的屏幕版本中的一个错误,因为我的屏幕
4.00.03jw4 (FAU) 2-May-06
没有显示该错误。如果可能的话,我建议升级。如果你无法升级屏幕,你需要想办法为其提供终端。不幸的是,我不知道该怎么做。似乎在某些版本的 PHP
proc_open()
可能能够做到这一点,至少如果 PHP 使用正确的选项编译的话,但是 显然该功能已经已删除。一种可能的远景可能是使用
expect
,如果它安装在你的系统。编辑:或者按照 tMC 建议执行并使用
posix_kill($pid, SIGTERM )
。不过,您需要首先找到会话的进程 ID。 (您可能可以 grepps
的输出或者如果您不担心抵押品,则可以使用killall
。损害。)I think this is probably a bug in the version of screen you're using, since the one I have,
4.00.03jw4 (FAU) 2-May-06
, doesn't exhibit it. I'd recommend upgrading, if possible.If you can't upgrade screen, you need to figure out some way to provide it with a terminal. Unfortunately, I'm not sure how to do that. It seems that in some versions of PHP
proc_open()
may have been able to do that, at least if PHP was compiled with the right options, but apparently that feature has been removed.One possible long shot could be to use
expect
, if it's installed on your system.Edit: Or just do as tMC suggests and use
posix_kill($pid, SIGTERM)
. You'll need to find the process ID of the session first, though. (You could probably grep the output ofps
for it. Or just usekillall
if you're not worried about collateral damage.)