Answer the question
In order to leave comments, you need to log in
How to handle errors in PHP, specifically WebSocket connections?
The question for me is "systemic", that is, for the solution of which there is not enough knowledge and it is not known how to approach it.
From the menu via Ajax, the connection function via WebSockets is called. If the WS-server does not respond, then the message "probably an error connecting to the server" is returned from the function. I would like to display my message on the screen. If errors are disabled, then everything works, but I would like to implement error logging (if there is a reliable way, I will be grateful for the tip).
The option to parse the response from the "error: function (response)" branch does not suit me because of the long output, which I would like to write to a file (the user does not need it). Questions:
1 Is it possible to send along with the error (as an array element) and your own code/description of the error?
2 Is it possible somehow to make Ajax not respond to the error and handle the "success: function (response)" branch?
3 Is there another output parameter combining both branches "success + error" in which I would place the analysis of the answer?
Answer the question
In order to leave comments, you need to log in
If possible, then I’m ready for this option - the text that I formed is placed in the error code, how can I get the resp value in JS ? I understand that the topic is PHP, but suddenly I'm just slowing down and everything is simpler than it actually is.
The answer was received via console.log(response['responseText']).
.
Warning : fsockopen(): Unable to connect to
localhost : 7777 resp ":"...}
Is it possible to send along with the error (as an array element) and your error code/description?Of course, exceptions are usually used for this. Not everywhere, but in many cases they work fine. Another thing is that there are 2 nuances:
but i would like to implement error loggingI hope you understand that it is impossible to do anything about this from the client side, but from the server side there is an error log, if these are not logic errors, which are not system errors, but rather incorrect behavior (such as "the field is not filled" or " Unacceptable symbols"). These can also be logged, but firstly - what's the point ?, and secondly, it's all the same to implement it with puff. And of course there will be no errors like "server not available".
2 Is it possible somehow to make Ajax not respond to the error and handle the ": function (response)" branch?yes, more precisely, you just need to not process the result in success. See below.
3 Is there another output parameter combining both branches "success + error" in which I would place the analysis of the answer?complete
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question