2013-04-16 06:33
浏览 105


I have a fairly big web application build with SproutCore and PHP as backend. What I want now is to use websockets to update my client application in real time. From what I know, PHP is really bad to handle persistent connections. So I've been thinking that I could use Go to handle the websockets connections and call my PHP scripts each time a request is received (this package seem to make it possible).

So my first question is, do you guys think it's a good idea (and a viable idea, I haven't been able to find people doing so) or should I stick with PHP ?

If I use Go to handle the websockets connections I've also been thinking that I could progressively move away from PHP to only use Go (since it is a lot faster than PHP). If I do that, I will have to be able to call some Go package from PHP. Can this be done with the PHP exec function ? Is there a better way ? And again, is that a good idea ?

图片转代码服务由CSDN问答提供 功能建议

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongliuxia9495
    dongliuxia9495 2013-04-16 06:37

    Go is a natural fit for websocket servers. I've built websocket servers in Go and have been extremely happy with how it all worked out. I have one service handling 300k users a month on a Go websocket server and it barely uses 1% CPU of an Amazon AWS micro instance. Couldn't be happier.

    Websockets really need event driven frameworks like Go and Node.js in order to maximize server resources. Forked web processes like PHP consume far more resources than an event driven framework.

    If you need to call Go from PHP at some point, I suggest using API calls. Although exec would work too.

    点赞 评论
  • duanhuiqing9528
    duanhuiqing9528 2014-02-13 17:41

    It is an old question, but my two cents on this subject...

    There is a very good php library that does exactly what you are asking for - websockets. It is called Ratchet. I would not use node.js (over hyped) or go when php can do exactly the same thing and it is the language that I am most comfortable with. In majority of cases, little gain in performance over websockets is not worth switching stack.

    Other useful links if you plan on using Ratchet:

    点赞 评论