Giter Site home page Giter Site logo

Comments (13)

materkov avatar materkov commented on July 27, 2024 2

I think you should take a look at 'timeout' option in Client.

from websocket-php.

kensoh avatar kensoh commented on July 27, 2024 2

Also want to add that it is not because PHP is a lousy language. It is because PHP is designed primarily for use on server side for content generation, while JavaScript was originally designed to be used on client side for content consumption. To implement a websocket client to consume and send websocket messages I guess is not really the goal of PHP language, so it is not built into the language.

EDIT - so how happy I am when I saw this client by Textalk. The best thing is it works out of the box (even without updates for 2 years) for my use case. That made me really like the project.

from websocket-php.

ryancwalsh avatar ryancwalsh commented on July 27, 2024 2

This worked out better for me: ratchetphp/Ratchet#627 (comment)

from websocket-php.

kensoh avatar kensoh commented on July 27, 2024 1

For my use case it is straightforward. After sending I just keep looping to read the response. Thus no error. The websocket server in my use case is Chrome. Below is snippet of the full source code for https://github.com/tebelorg/TagUI/blob/master/src/tagui_chrome.php

$client->send($tagui_intent); $intent_result_string = ""; // keep reading until chrome replies with message
while ($intent_result_string == "") {try {$intent_result_string = trim($client->receive());} catch (Exception $e) {}}

from websocket-php.

szado avatar szado commented on July 27, 2024

I have the same problem, any suggestions?

from websocket-php.

l0rb avatar l0rb commented on July 27, 2024

+1 getting the " Empty read; connection dead?" error pretty often, usually within less then 1 minute of starting the client

from websocket-php.

kensoh avatar kensoh commented on July 27, 2024

I'm interested in this issue and wonder if Daniel has found a solution? The default timeout is 5, I'm thinking isn't this reasonable with enough buffer time for modern client to server communication, or would it be recommended to double it to 10 and if there are any downsides to doing so.

from websocket-php.

jedimdan avatar jedimdan commented on July 27, 2024

@kensoh I'm afraid I gave up. My work around was to write a simple 1 file node app in javascript (it's so much easier to get a WebSockets client working in JS than in PHP) that subscribes to a server and passes the content over to the PHP app to do the rest by executing a command.

from websocket-php.

kensoh avatar kensoh commented on July 27, 2024

@jedimdan I see.. oh yes, it is in-built into JavaScript and only takes few lines to code to send and receive the message. That sounds like a cool way to implement, thanks for sharing :)

For my use case, I need concurrency, in the sense I need to be able to receive events during execution of a JavaScript function. That is not possible with single-threaded JS unless I use async/await or promises, which are not yet supported by the underlying tool that my project is based on. So my other reasonable choice is to implement it as a separate PHP thread and then pass the data to my JS code for processing (through simple I/O files on the local file system).

from websocket-php.

rabashani avatar rabashani commented on July 27, 2024

I am getting the same error

Empty read; connection dead? Stream state: {"crypto":{"protocol":"TLSv1.2","cipher_name":"ECDHE-RSA-AES128-GCM-SHA256","cipher_bits":128,"cipher_version":"TLSv1/SSLv3"},"timed_out":false,"blocked":true,"eof":true,"stream_type":"tcp_socket/ssl","mode":"r+","unread_bytes":0,"seekable":false}

did anyone solve this? @kensoh
or someone can share a different solution
@jedimdan can you share your solution?

from websocket-php.

Chevil5 avatar Chevil5 commented on July 27, 2024

I got that error. In my case problem was because of new line characters in the string.

from websocket-php.

sirn-se avatar sirn-se commented on July 27, 2024

The "timed_out": true implies that the stream has been closed by server because of its time out setting. The client is expected to throw exception on failed send/receive operations, no matter the cause.

In the example code above, it's easily fixed by putting the $message = $client->receive() inside a try/catch clause. On the next while iteration, it will reconnect and continue reading.

from websocket-php.

sirn-se avatar sirn-se commented on July 27, 2024

Current documentation explains how to perform an error safe listener using try/catch and loop. Closing this issue.

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.