Can websocket (or can) replace ajax?

Source: Internet
Author: User
My main language is PHP. I have an idea this time. Can I use socket to replace ajax without considering compatibility? Can I do this (or shouldn't I do it? Will the performance be improved? Will consumption increase? I hope you can answer this question for me... my main language is PHP. I have an idea this time. Can I use socket to replace ajax without considering compatibility?

Can I do this (or shouldn't I do it?
Will the performance be improved? Will consumption increase?

I hope you can answer this question for me (I hope this is not a silly question ...), Thank you.

Reply content:

My main language is PHP. I have an idea this time. Can I use socket to replace ajax without considering compatibility?

Can I do this (or shouldn't I do it?
Will the performance be improved? Will consumption increase?

I hope you can answer this question for me (I hope this is not a silly question ...), Thank you.

Yes, the performance of the page must be improved, because the Socket has its own HTTP, that is, it can be held for a long time, and there is no header content, these benefits are significantly improved for performance. In terms of consumption, the consumption on the server is certainly a little larger. After all, you have to Hold N links for N accesses. This fact is there.

Compatibility is not considered.

  • If you have high requirements on real-time performance, you can use websocket because the latency is much lower, such as message pushing and other functions. In addition, it is better to maintain a connection when frequent communication occurs.
  • If you just make a query from time to time, you should use ajax.

Personal opinions, for reference only ~

Right, now there are two kinds of requirements. To improve real-time performance, only the polling time can be reduced, and the server cannot afford it.

So I thought of the socket. The problem was that I didn't try it before, and I don't know how to consume it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.