How sockets work in php

Asked

Viewed 194 times

2

I’ve been needing to work with real-time updates lately, so I discovered the sockets, more specifically to use in php. I’m making a simple example based in those codes, the problem is that when sending the form the page generates refresh the same way, in case I would have to use jQuery.ajax to send the request without refresh? I’m a little lost.


I understood more or less how it works after a long search on the internet, but when sending a message with socket.send() the server returns it: GET / HTTP/1.1 Host: 127.0.0.1:3500 Connection: Upgrade Pragma: no-cache Cache-Control: no-cache Upgrade: websocket Origin: http://127.0.0.1 Sec-Websocket-Version: 13 User-Agent: Mozilla/5.0 (Windows NT 6.1) Applewebkit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36 Accept-Encoding: gzip, deflate, br Accept-Language: en-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4 Sec-Websocket-Key: 9cUxYx7abplnX8+wXBvZug== Sec-Websocket-Extensions: permessage-deflate; client_max_window_bits

  • 1

    Do you want to simply submit a form without refresh? Because if you want to make an application in real time, you would really need a larger structure, like Node.js + Socket.io, but if you just want it not to refresh when submitting a form, it can be done simply with AJAX, yes.

  • Actually I was thinking of a simple game, to play with friends, where the character moves and everything, as I have developed with php for some time, I felt more comfortable developing with it. Can’t php sockets work that way? I mean, can’t you create a simple game with php sockets? If not, what language would you recommend me? I was thinking of Ruby, I heard very well about you.

  • For games you will need to use sockets, yes. I do not understand much of sockets, but know that with AJAX will weigh and get delay (ping) high. I recommend that you take a look at what I mentioned above: Node.js + Socket.io This pair is widely used in real-time applications. Both technologies have documentation available on the internet and are based on javascript.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.