PHP 和 IRC 以及 Shell
我正在与一个大约有 100 个用户的封闭社区网站(基于 PHP)合作,我们实现的功能之一是 ajaxshoutbox,当用户登录时,它在网站首页上充当“聊天室”。团队正在使用私有 irc 服务器进行协作,并且在一个频道中我们正在运行一个测验机器人。我们提出了尝试制作一个网络界面来通过我们的网站连接到 irc 的想法,以便我们网站的所有(非技术精通)用户都可以参加我们的 irc 测验。
现在,我不是 IRC 专家,但我研究了一些 PHP-IRC 教程,在我看来,为了连接到 IRC,PHP 需要保持一个开放的连接..这意味着我们需要执行彗星式技巧,让 PHP 脚本执行而不会超时。然而,这意味着如果用户离开页面或关闭选项卡,我们就会失去对该 php 执行的控制。如果发生这种情况,我们可能会想出一种方法来停止连接,但即便如此,如果用户导航回聊天室,他也必须重新连接到 irc。
我们想要实现的是一种让用户永久连接到 irc 服务器的方法,即使他们没有登录该站点。开发团队在我们的一台服务器上都有 shell 帐户,我们使用 screen 和 irssi 来保持连接。我认为应该可以通过始终连接到 irc 的 shell 帐户将 php 脚本连接到 irc。由于我们的用户数量有限,为所有用户设置 shell 帐户不是问题,但我还没有找到缺少的链接 - 一个允许以某种方式访问 php 的命令行 irc 客户端。
有人有什么建议吗?
I'm working with a closed community site (PHP-based) of about 100 users, and one of the features we've implemented is an ajax shoutbox that works as a "chatroom" on the site frontpage when users logged in. The dev team is using a private irc server for collaboration, and in one channel we're running a quizbot. We came up with the idea to try and make a web interface for connecting to irc through our site, so all the (non-tech-savvy) users of our site can participate in our irc quizzes.
Now, I'm no IRC expert, but I've looked into a few PHP-IRC tutorials, and it seems to me that in order to connect to IRC, PHP needs to maintain an open connection.. which means that we need to do a comet-style trick and let the PHP script execute without timing out. However, this means that if the user navigates away from the page or closes the tab, we loose control of that php execution. We could probably figure out a way to stop the connection if this happens, but even so the user would have to reconnect to irc if he navigates back to the chatroom.
What we want to achieve is a way for users to be perpetually connected to the irc server, even if they aren't logged in to the site. The dev team all have shell accounts on one of our servers, and we use screen and irssi to stay connected. I figure it should be somehow possible to have a php script connect to irc through a shell account that is always connected to irc. Because of our limited number of users, it isn't a problem to set up shell accoutns for all of them, but I haven't yet figured out the missing link - a command-line irc client that allows php access in some way.
Anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是运行 BNC,它基本上是一个代理,用于维护与IRC 服务器,您的 PHP 脚本可以在需要时连接到它。您需要设置一种方法来识别用户与 BNC 软件的 PHP 会话、设置会话超时等,这一切都取决于您正在使用的特定软件及其可用选项。
或者,用 Python 编写一个特殊用途的代理或维护 PHP 会话的 IRC 连接列表的东西也不会那么困难。
您可能也不希望每个 PHP 会话有一个 IRC 连接,IRC 通道上的单个持久机器人连接可以轻松地在每条消息中包含一个用户名,以标识发送该消息的 PHP 用户。
One option would be to run a BNC, basically a proxy that will maintain connections to the IRC server, and your PHP script can connect to it when it needs to. You'd need to set up a way to identify a user's PHP session to the BNC software, set session timeouts etc. that would all depend on the specific software you're using and its available options.
Alternatively it wouldn't be that hard to write a special purpose proxy in say Python or something that would maintain a list of IRC connections for PHP sessions.
You also might not want one IRC connection per PHP session, a single persistent bot connection on the IRC channel could easily include a username in each message identifying the PHP user that sent it.