Comments (6)
Learning Composer is well worth the effort. And it's not that complicated.
- Go to the directory where you're code resides.
- Run
curl -s https://getcomposer.org/installer | php
- Run
php composer.phar require phrity/websocket
You should now have a composer.json
file containing dependencies, and a directory vendor
with this repo and its dependencies. In your local file use require 'vendor/autoload.php'
to get all classes loaded automatically. That's it.
You should not download this code yourself, and not run composer in the downloaded directory (that's why you get that error), but let Composer handle the dependencies for you.
from websocket-php.
Step # 2 doesn't work...
-bash: PHP: command not found
FYI, I'm under CentOS 7 with PHP 8.2
Also, when you wrote "You should not download this code yourself, and not run composer in the downloaded directory" then what does step # 1 mean? I'm so confused! I've downloaded the GitHub files. I have the directories like examples, lib, tests and bunch of files like .gitignore, composer.json, COPYING.md, Makefile, phpunit.xml.dist, README.md. It's all there.
from websocket-php.
All the references to php
above is for the PHP binary. Replace them, if necessary, with the search path you normally use when running PHP.
Composer will download the library, its dependencies, and create the autoloader for you.
So you only need to install Composer itself. Once in place, it will manage your projects dependencies.
from websocket-php.
Alright, so what I did to install this is:
- Create an empty folder
- In bash, run
composer require textalk/websocket
in that empty folder - chmod/chown -R all the files that step 2 produced
This seems to work. I can start the server and connect ONE (1) client script to the server and it sends/receives correctly.
However, the issue that I'm now running into is that I cannot seem to connect more than a single client at a time to it. The server script I'm using right now is: examples/echoserver.php
When I attempt to connect a second client to it, initially it seems to work (it outputs "Creating client" and then "Sending text" or whatever), but all commands time out and are never processed by the server script at all. Is there a reason why it does not accept more than 1 client at a time? How can we make it accept and serve 100 connections at a time? The client script I'm using is: examples/random_client.php
I can see in vendor/textalk/websocket/lib/Server.php that the accept() function arbitrarily blocks other incoming connections. Why?
/**
* Accept a single incoming request.
* Note that this operation will block accepting additional requests.
* @return bool True if listening.
*/
public function accept(): bool
{
$this->disconnect();
return (bool)$this->listening;
}
EDIT: After even more investigating, it seems like your WebSocket implementation does not use non blocking sockets (using the native stream_set_blocking() function)... Is there a reason for this? I notice that the current implementation uses fread() in vendor/textalk/websocket/lib/Connection.php which will literally block the whole app until at least 2 bytes come in from the most recently connected socket, making this impossible to use with more than 1 client at a time.
from websocket-php.
Well, I came to the conclusion that this is very far from an usable multi-client WS and it has way too many dependencies than is really required. I went with the following for my project: It's a PHP 8.2 compatible multi-client WS server that works perfectly fine and it even supports WSS (WS over SSL so it's secure). Not sure how 152 files could ever beat this simple page of code, but it works flawlessly and it's super easy to tweak too. Hope it helps anyone: https://www.php.net/manual/en/function.stream-socket-server.php#125540
Good luck.
from websocket-php.
Well, this repo is a full implementation of the websocket protocol. It's a bit more to it than just I/O.
If you prefer to build your own implementation from scratch, this is not the code library you've been looking for.
from websocket-php.
Related Issues (20)
- Maximum execution time on Header block HOT 3
- Mozilla is not recognized as an internal or external command HOT 1
- Connection with WSS HOT 3
- How can I use this package with laravel? HOT 8
- Update to last version and websocket wss://ws-api.exmo.com:443/v1/public do not work HOT 3
- stream_socket_client(): Unable to connect to ssl HOT 1
- Client Ping/Pong broken in 1.6 HOT 5
- The current version only works on PHP8 HOT 1
- Looping receive() is not working HOT 3
- How to set proxy IP HOT 3
- failed to connect wss HOT 1
- Composer not load method HOT 1
- NOTE: TexTalk replaced by sirn-se/websocket-php
- Upgrade psr/http-message to ^1.1 || ^2.0 HOT 3
- heart break
- permessage-deflate problem HOT 1
- sometimes connection refused, but ends in fatal error HOT 1
- Does this socket work on https?
- 初次使用后的一些体验与几点疑惑,期望得到大佬们的一些帮助,谢谢!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocket-php.