1

I recently took a course on AngularJS, and quite frankly I loved the concepts of a website that fetches json to handle subsequent requests, however I still feel like Javascript is far too slow for what I want to do on a server.

I have recently been hired to build an online auction website. I built two mockups, one with AngularJS and one in PHP. The PHP website is much faster on initial load and handling large requests, but the AngularJS-powered site is much more responsive on simultaneous requests, and writing JavaScript and HTML frontend is much easier, so I got to thinking that I might just make a counterpart to AngularJS using PHP, JS, and HTML, giving me the best of both worlds. As I go forward in implementing the design, I started to question if AJAX was the right tool for the job. It seems like I could use a simple node.js websocket server as an intermediary to between the client-side JS and PHP, passing commands from the client over websockets to the server, then passing the data back.

Would you consider this premature optimization, and if not, would removing the HTTP overhead really make much difference at all in terms of bandwidth and request size?

  • 2
    You probably already know more about this than we do, since you have access to your application's actual requirements. – Robert Harvey Jul 7 '14 at 22:26
  • Right, using web sockets is not the catch-all solution. It really depends on your project. See this question on Stack Overflow for more details. – Léo Lam Jul 8 '14 at 21:32
1

If you want typical request-response client-server communication use ajax.

If you want bidireccional communication and for example sending updates from the server to the clients use web sockets.

"It seems like I could use a simple node.js websocket server as an intermediary to between the client-side JS and PHP, passing commands from the client over websockets to the server, then passing the data back."

I don't see the point in doing something like that. If you want to use websocket use node for the server side of you application, why do you want to use node.js only as a "websocket proxy" and use php for server side operations?. What is the justification for this complexity?

  • because i don't know how to write a websocket server in php,whereas there are hundreds of tutorials on node.js – r3wt Jul 9 '14 at 6:02
  • Why don't simply write your server side in node.js instead of php? – AlfredoCasado Jul 9 '14 at 10:17
  • its far too slow for what i'm doing. I'm using facebooks HHVM – r3wt Jul 9 '14 at 10:26
  • If you are concerned with performance include an extra indirection layer with node.js can be a problem. I'm not an expert in php, but you can ask about implementing web sockets directly with php if you really need them. – AlfredoCasado Jul 9 '14 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.