sirn-se / websocket-php

[php-lib] WebSocket client and server in PHP
Other
105 stars 17 forks source link

>onText callback #71

Closed sacOO7 closed 2 weeks ago

sacOO7 commented 1 month ago

Is code written inside >onText blocking or nonblocking? Does this library make use of php fibres to achieve concurrency ? How is this library different from https://github.com/amphp/websocket-client and https://github.com/ratchetphp/Pawl

sacOO7 commented 1 month ago

If it uses fibers internally, why isn't is build on top of ampPhp and reactPhp instead

sirn-se commented 1 month ago

Hi, No simple answers to your questions but I'll give it a try.

This library uses a custom coroutine setup, similar to Fibers but limited/optimized for actually use. I have considered switching to Fibers but as the functional benefit is pretty low it's not a priority at this point.

The listener callbacks are invoked after a message have been read from stream, so they're not blocking as such - unless you add blocking code in them.

I'm not familiar with mentioned libraries, but maybe someone else can make a comparison.

sacOO7 commented 1 month ago

Thanks for the answer ! Btw, I was interested in your custom coroutine setup : > Can you point me to the code ?

sirn-se commented 1 month ago

The run loop is in the start() method of Server and Client respectively. The "queue" is populated by waitRead() that in turn uses stream_select(). This way the entire instance share a single wait state, connections will never block each other.

So it's not a generalized coroutine setup (although there is a onTick(...) listener that allows adding custom code).