php-websocket | Simple WebSocket server implemented in PHP | Websocket library
kandi X-RAY | php-websocket Summary
kandi X-RAY | php-websocket Summary
Simple WebSocket server implemented in PHP.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Creates a JSON payload from a JSON string .
- Make application payload .
- Makes server payload .
php-websocket Key Features
php-websocket Examples and Code Snippets
Community Discussions
Trending Discussions on php-websocket
QUESTION
I am coding a simple chat in 100% PHP, that uses WebSocket (with no external library, like in this article).
Obviously, this requires a constantly-running PHP script / daemon / event-loop (similar to how Node.JS works), that we start with:
...ANSWER
Answered 2021-Jan-31 at 01:02In websockets.php
I would create a conditional statement that checks whether the button was clicked (on/off settings from the database). Some pseudo-code:
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 have following code
index.php
...ANSWER
Answered 2017-Mar-30 at 01:11My unswer NO. You can not fully use the websocket client logick, using only the server part(for example php). Because the server side know anything about the browser. Server - receives a request and returns a static result. All magic in the browser is javascript. Javascript can dynamically listen all user events, post a query to server and insert a response from the server to the page. Websocket can not work without javascript in browser. This is WebSocket definition:
WebSockets are a bi-directional, full-duplex, persistent connection from a web browser to a server. Once a WebSocket connection is established the connection stays open until the client or server decides to close this connection. With this open connection, the client or server can send a message at any given time to the other. This makes web programming entirely event driven, not (just) user initiated. It is stateful. As well, at this time, a single running server application is aware of all connections, allowing you to communicate with any number of open connections at any given time.
The only thing you can do, is learn node js. It will allow you to write the browser (client) part and server part on one language - javascript. But however this will be different parts of application, and you will use different approaches, to program each part
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-websocket
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