PHP-Websockets | A Websockets server written in PHP | Websocket library
kandi X-RAY | PHP-Websockets Summary
kandi X-RAY | PHP-Websockets Summary
A Websockets server written in PHP.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Do a handshake
- Run worker loop .
- Frames a message
- Define a message .
- Extracts headers from the message
- Split a packet
- Disconnects from a socket .
- Convert a string to hex
- Loop all connected users .
- Apply the mask
PHP-Websockets Key Features
PHP-Websockets Examples and Code Snippets
Community Discussions
Trending Discussions on PHP-Websockets
QUESTION
Before getting started with the actual question, I’d like to make a notice of being an extreme beginner to the world of web sockets using PHP. As a matter of fact, I’m still trying to grasp the very basics of it. I do however have lots of experience with sockets overall, from languages such as Java.
Upon doing my research, I stumbled upon the tutorial from PHP builder, whereas I think myself to having learned how to set socket connections up using this simple library.
ProblemUnto the problem we go. For a development server, I have chosen to go with XAMPP—it’ss sort of stayed with me from my Windows days, many years ago. At this very moment, I am using the terminal UI for XAMPP in Ubuntu—meaning, I launch the XAMPP server and then do a killall
should I ever wish to close it.
In the tutorial mentioned above, you enter this information into your PHP document where you keep your server socket:
...ANSWER
Answered 2018-Apr-24 at 10:10The problem that was occurring at the time was the PHP code being displayed as raw data in the terminal whenever run. I was using short opening tags at the time and did have them enabled in the configuration.
I did however, resolve the issue, by rewriting the code to use the full opening PHP tags . Perhaps there was more things to configure, maybe the version of PHP I was using was broken. Who knows?
QUESTION
I've tested several libraries (workerman and PHP-Websockets) but in all cases I have the same issue - when I open clients page everything is all right, I have websocket connection with my server, but later it disconnects automatically in a few minutes or less. Is it known issue or is there any methods to handle it? Or should I simply implement some function to force recconection if websocket fails?
This is a code sample for workerman
Server test_ws.php
ANSWER
Answered 2018-Feb-24 at 04:52As written in this article: "In case of established websocket connection, server or firewall could timeout and terminate the connection after a period of inactivity."
This is the solution!
Modified client's page:
QUESTION
I was able to setup WebSocket on Azure.WebSockets enabled on Azure
But my issue is : how to start the PHP ws server?
I have used this sample implementation https://github.com/ghedipunk/PHP-Websockets successfuy on my computer but I am not able to start the server in MS Azure.
...ANSWER
Answered 2018-Feb-06 at 06:29All Azure Web Apps run in a secure environment called a sandbox. In the sandbox, each app is processed by Microsoft IIS. An app runs through PHP's Command Line Interface (CLI) is not allowed. For more details, please refer to Azure Web App sandbox.
In order to be able to run PHP-WebSockets
in Azure, you need to host in something like a Virtual Machines, Cloud Services, or Containers, rather than Web Apps.
QUESTION
I am new to WebSocket
world and even after a week, I still could not find how to use it with PHP
without using any 3rd Party Library. Or not sure if it is even possible.
I have 3 questions,
1) Do we must need to use some 3rd Party APIs or Libraries like Ratchet, PHP-Push-WebSocket or PHP WebSocket to enable PHP to communicate over WebSocket protocol?
2) If your answer to above question is yes then what is the advantage/purpose of using Apache's mod_proxy_wstunnel
?
3) If I use any PHP WebSocket 3rd Party Library, then do I still need to enable and use Apache's mod_proxy_wstunnel
? If No, then again what is the purpose of Apache's mod_proxy_wstunnel?
I went through this Using go-websocket behind Apache mod_proxy_wstunnel. In this question, the OP has indicated some go-websocket but unfortunately the link is giving 404 Error and hence I cannot understand if the user has used any 3rd Party API.
Any help would be highly appreciated. Thanks in advance.
...ANSWER
Answered 2017-Oct-14 at 12:29PHP is not created for WS. Of course you can do this, but it is full of while (true)
and fsock_open
[*]. And you have to have access to the shell to run the WS-server with php-cgi. (usually)
Choose a language that supports threads / asynchronous communication. Now on the top is Node.js. In addition, better use dedicated libraries to support older browsers, etc. If you are thinking about alternatives to ajax then you can use socket.io. If you want to create one-to-all communication (eg chat, broadcast messaging), go one step further and use one of the Bayeux
implementations, for example: Faye.
The mod_proxy_wstunnel
extension adds an extra layer to the WS server. Depending on the configuration, it can support DDoS, queue, load-balancing, local port swapping, and https support. But better use this for nginx.
So, for test you don't need mod_proxy_wstunnel
, and on production, you should add an extra layer of security, eg NGINX ws tunelling.
[*] Sorry, I made some mistakes. PHP has native support for WebSockets. That content is going to set you negatively to WS in PHP.
Websockets are events, and PHP is poorly managed with it.
QUESTION
My websocket file:
...ANSWER
Answered 2017-May-02 at 14:24Try to use SERVERNAME
instead localhost.
From PHP RATCHET:
QUESTION
I developed a multiplayer card game and therefore used a websocket. To implement the websocket in php, I used this library
I'v put it to my ubuntu server and the program works fine on Chrome Browser and in Firefox (The frontend is implemented using Javascript). Using the Edge Browser, there is an error stating "ReferenceError: WebSocket is undefined". But on the internet I have read that Edge should normally support websockets.
I already checked, whether the document mode is another IE version, but it is set to edge as well. The exact version is 11.0.0600.18537.
The following is my code (althoug I don't think that is is a problem with it as it works in the other browsers)
...ANSWER
Answered 2017-Feb-10 at 11:47Are you sure you are actually writing WebSocket
in your code? The error says that Websocket
is not defined (with non-capitalized s
).
The actual classname is WebSocket
with a capital S
.
Please confirm that the code you pasted as an example is really the same as the one you have in your application.
EDIT
After some further discussion in the comments I believe that WebSocket support might be disabled in your browser. WebSocket should be supported in your browser version (11.0.0600.18537) according to my own experiment and Can I Use.
QUESTION
I am running a websockets server using https://github.com/ghedipunk/PHP-Websockets/blob/master/websockets.php on an Ubuntu 16 box with PHP7
After 256 users connect to the websocket, it stops taking connections and I can't figure out why. In the client, I get a 1006 error code (connection was closed abnormally (locally) by the browser implementation) and no further information. The websockets request doesn't appear to make it to the websockets server (which normally echos "Client Connected" right after a socket connection is made).
In the connect() function, one of the things I do is echo the count of the number of users, sockets and overall memory usage to the log. This problem occurs whenever the user count hits 256 (at which point the socket count is 257 and memory usage around 4Mb). The fact that it happens at 256 makes me think that a limit is being hit somewhere, but I can't find that limit. If I restart the websockets server, everything works fine again.
From my investigation so far, I have tried and checked:
- ulimit (says it's unlimited)
- MySQL connection limit (was set to default, now is 1000, but that didn't help)
- Increased the PHP memory limit (because why not, just to see)
- SOMAXCONN is set to 128, so I don't think this is the problem, but I would have to recompile PHP to test it. I haven't tried this yet.
- Apache: The message I get when the problem occurs is:
[proxy:error] [pid 16785] (111)Connection refused: AH00957: WS: attempt to connect to 10.0.0.240:9000 (websockets.mydomain.com) failed
, which doesn't tell me much about anything. Apache is running MPM prefork and I have increased the spare servers and MaxRequestWorkers
I am open to any suggestions as to where to look next or how to get more detail out of the "Connection Refused" error log from apache!
Thanks
...ANSWER
Answered 2017-Jan-25 at 15:18It's Apache that holding you up. Try setting the following in your conf file...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PHP-Websockets
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page