Giter Site home page Giter Site logo

Comments (6)

sirn-se avatar sirn-se commented on June 30, 2024

Learning Composer is well worth the effort. And it's not that complicated.

  1. Go to the directory where you're code resides.
  2. Run curl -s https://getcomposer.org/installer | php
  3. 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.

MarcTremblay1981 avatar MarcTremblay1981 commented on June 30, 2024

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.

sirn-se avatar sirn-se commented on June 30, 2024

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.

MarcTremblay1981 avatar MarcTremblay1981 commented on June 30, 2024

Alright, so what I did to install this is:

  1. Create an empty folder
  2. In bash, run composer require textalk/websocket in that empty folder
  3. 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.

MarcTremblay1981 avatar MarcTremblay1981 commented on June 30, 2024

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.

sirn-se avatar sirn-se commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.