【发布时间】:2013-03-04 10:25:10
【问题描述】:
我需要在 PHP 中建立一个持久的套接字连接,但不知道如何实现。目前,当我发送 SMS 消息时,我 a)打开套接字连接 b)发送消息(通过 SMS/SMPP)和 c)关闭套接字连接
但是我不需要一直打开和关闭连接。相反,我需要
- 2 persistent connections that maintains connectivity to an SMSC (SMS centre) and reconnects when a timeout occurs.
- One persistent connection for reading SMS and one for sending SMS.
- Automatic restart/recovery (i.e. when memory issues arise)
- Automatic looping to act as listener for incoming events such as receiving incoming delivery receipts and sms messages, as well as 'ping' (enquire link) to keep SMPP connection alive.
更新:想知道是否有人使用以下方法实现了上述目标:https://github.com/shaneharter/PHP-Daemon
【问题讨论】:
-
php.net/manual/en/function.shm-put-var.php 在 cmets 中有很好的读物。
-
我在这个项目中完成了这个要求:github.com/nimf/phpesme我们有一种看门狗脚本,可以确保 rx、tx 和处理程序进程始终运行并在退出时重新启动。
-
谢谢尤里。几周前,我会认真考虑解决方案,例如您提供链接的解决方案。但是最近几周我已经将所有 PHP/SMPP 升级到 Java/SMPP 并且没有回头 :-)
-
@user1746582 我认为 PHP-Daemon 库非常适合您。我在一些项目中使用过它,从从队列中读取作业并在线处理它们的简单守护程序,到最近使用后台工作者的更复杂的应用程序。 (获取传入的套接字连接,侦听作业请求,然后将其发送给后台工作人员以保持主进程畅通。在没有线程的 PHP 等语言中,这确实是您所希望的最好的)
标签: php sockets daemon smpp persistent-connection