I am using memcache in PHP but I am struggeling how to handle the error it throws at me.
I use the addServer method to add servers but while still in production I sometimes don't have it turned on and the connection obviously can't be established. This is all expected but instead of an exception I get a notice I can't get ride off.
Notice: MemcachePool::set(): Server 192.168.1.2 (tcp 11211, udp 0)
failed with: A connection attempt failed because the connected party
did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
(10060)
How can I catch/handle this notice/error?
You could either use a custom error handler so you can catch the notice when it happens and handle it appropriately, or check if the connection works after you execute addServer() and handle the failed connection there. For this check out this comment in the docs.
Related
Connection could not be established with host smtp.mailtrap.io :stream_socket_client(): Unable to connect to tcp://smtp.mailtrap.io:2525 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)" this is the error message that is displayed
It’s related to your environment file .env and the email setup. Its going to need to be debugged as to what the email setting should be and then if they emails are even getting out from your server/localhost.
I’ve got a PHP communications server running using stream_socket_server() and stream_socket_accept(), a fairly complicated thing which uses SSL connections and certificates to be certain that the remote side is authorized to connect to the server. One of the things which is coming up in my logs are the failed connections. I’m trying to provide more details on these connections for security purposes.
I’m currently getting most of my error detail on the failed connections by setting an error handler for the stream_socket_accept() call:
public function on_ssa_error($errno, $errstr)
{
$this->ssa_error .= " ERROR [$errno]: $errstr\n";
}
public function on_select_read()
{
$this->ssa_error = "";
set_error_handler(array($this, "on_ssa_error"));
$rsocket = stream_socket_accept($this->ss, 0);
restore_error_handler();
if ($rsocket !== FALSE)
// Finish setting up the socket connection and start using it
else
// Report the error in $this->ssa_error
}
…when I have a failed connection, I tend to get errors like this:
ERROR [2]: stream_socket_accept(): SSL operation failed with code 1. OpenSSL Error messages: error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate
ERROR [2]: stream_socket_accept(): Failed to enable crypto
ERROR [2]: stream_socket_accept(): accept failed: Success
…which is partly useful in that it identifies the cause of the bad connection as a bad certificate, but I’d really like to have something indicating where the bad request came from, ideally the IP address or Mac Address of the source.
Is there any way to get the IP address of a failed connection using the stream_socket_xxx code? I know it’s possible to get the IP address of an accepted connection, but I’m stumped trying to figure out a way of getting it on a failed connection.
I have a php file and all it contains is
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo file_get_contents("http://mywebsite.com/javascript-function.php");
?>
And for some reason it displays the following notice:
Notice: file_get_contents(): send of 24 bytes failed with errno=104 Connection reset by peer in /home/sites/mywebsite.com/public_html/index.php on line 6 Notice: file_get_contents(): send of 2 bytes failed with errno=32 Broken pipe in /home/sites/mywebsite.com/public_html/index.php on line 6
I have never come accross this message before so I have no idea what to do to solve it.
I have also tried using cURL but it outputs nothing and no error message.
A connection reset by peer error occurs in a datastream connection when either the remote host you are connecting to (i.e. mywebsite.com which you specified in the call to file_get_contents) terminates the socket connection on their end before the client is finished sending the request, or when the local network system detects a failure in connecting.
Some common root causes could be a firewall rule that is blocking the connection on either end or possibly a miss-configured web server. One way to narrow down the problem is to attempt accessing the same URL from a web browser on the same client that this script was run when the error occurred. If it works as expected, at least you know, it's not a firewall issue on the client. Begin digging into the web server's config files to troubleshoot the problem further. However, if the same problem occurs in a web browser then you should begin looking into your firewall rules on that client as well as the host's firewall rules if any.
So, we are coding a web chat client for our current IM, and i have one issue, socket_connect will NOT connect, and throws the "error Warning: socket_connect(): unable to connect [111]: Connection refused in /home/shadowri/public_html/zapf/personal.php on line 29" how would i get it to connect exactly, as it has to connect to the socket and send a handshake after that, then how would i get it to read every time they receive an message? i know its listening on that tcp socket, as our pc client uses it and simply connects directly then sends the handshake? am i missing something"
Either there is a firewall in the way or there is nothing listening at the IP:port you tried to connect to.
I am using Zend_Rest_Client to connect Zend_Rest_Server, everything seems to be alright, but when I try to get() from the server I recieve this error:
Zend_Http_Client_Adapter_Exception:
Unable to Connect to
tcp://localhost:80. Error #10060: A
connection attempt failed because the
connected party did not properly
respond after a period of time, or
established connection failed because
connected host has failed to respond.
in
C:\www\zf_1_72\library\Zend\Http\Client\Adapter\Socket.php
on line 148
here is code, which I use
$client = new Zend_Rest_Client('http://localhost/my_application/api/index/');
$client->auth($key);
$result = $client->get();
thank's for any advice
This thread suggetss the issue may be with the 'localhost' name - try using 127.0.0.1 instead.