Comments (13)
I think you should take a look at 'timeout' option in Client.
from websocket-php.
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.
This worked out better for me: ratchetphp/Ratchet#627 (comment)
from websocket-php.
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.
I have the same problem, any suggestions?
from websocket-php.
+1 getting the " Empty read; connection dead?" error pretty often, usually within less then 1 minute of starting the client
from websocket-php.
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.
@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.
@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.
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.
I got that error. In my case problem was because of new line characters in the string.
from websocket-php.
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.
Current documentation explains how to perform an error safe listener using try/catch and loop. Closing this issue.
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
- How to install this? HOT 6
- 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.