How to create a website server in PHP?

I searched the internet for two days trying to figure out how web sockets work. I am relatively new to Javascript and PHP because I started about two or three months ago.

I am very confused about what the Http protocol is and how to do a โ€œhandshakeโ€ with the server that I read about. Therefore, unfortunately, it is difficult for me to ask a more specific question than the one named in the title.

However, even more than I would like to answer the question in the title, I would really like a resource that will tell me in detail about web sockets, for example, a book or an online tutorial.

Any help is appreciated, thanks.

+7
source share
2 answers

Sockets in general are just TCP streams that you can send data to. HTTP is built on top of them. WebSockets are built on / in parallel with HTTP and allow you to send data back and forth to the browser in real time. Standard sockets can perform some of these functions, but browsers have tight protection, which makes it difficult to use standard sockets to communicate with them.

WebSockets are useful when you need to constantly connect to the server from a browser, real-time applications, or things like push notifications.

Unfortunately, I know little about the PHP implementation, but it looks like there is a library here: http://code.google.com/p/phpwebsocket/

Personally, I shy away from doing such things in PHP because PHP / Apache can be quite heavy, and since the socket is always open and someone is viewing the page, server resources can be used quite quickly.

Many people like to use NodeJS with socket.io, because then you can use JavaScript on the server and in the browser, but actually it depends on preferences. I would look at Socket.IO and find a language that has a good client.

Seems like this question might be helpful too. Using PHP with Socket.io

+9
source

Is this consistent with the bill?

http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/

If not, I can find something else.

+1
source

All Articles