PDO returning error when no error

Asked

Viewed 83 times

1

Randomly, I get the following error while upgrading my system:

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Cannot assign requested address

By error, it can not connect to the server, but the server is there, and is on, absolutely sure of that, because in other PC’s when you give this error in mine, in others continues normally.

There is no standard for this to happen, it is for no reason, sometimes when I update my page, or make some request via ajax, PHP returns this error, I do not need to do anything, just update one or two (sometimes much more) that it returns to work normally.

Detail, this occurs more often in my production PC (with Ubuntu 16.4) in my test (Win 7) occurs rarely.

This system is on an internal server (Debian 7), the network has a proxy and firewall, but my development Pcs do not go through either.

I’ve been having this annoying problem for a few days, any suggestion is welcome as I’ve tried everything I could think of.

NOTE: My database is relatively large.

Connection code is as basic as possible:

namespace MySQL;
class MySQLConector {

    /**
     * Receber a conexão
     * @return \PDO
     */
    public static function get_conn() {
        $database_url = '192.168.0.254';
        $database = 'database';
        $database_user = 'user';
        $database_pass = 'password';
        $PDO = new \PDO('mysql:host=' . $database_url . ';dbname=' . $database . '', $database_user, $database_pass);
        $PDO->exec("SET NAMES UTF8");
        //$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return $PDO;
    }

}
  • Is the number of requests to the system large? It may be that the server is not supporting handling all of them at the same time. Anyway, I think it’s interesting that you put the code in the question.

  • The amount isn’t much, but what some requests do are big things, but it’s a dedicated server, that error is the first thing in the system, it doesn’t even make the heaviest requests when it happens, nor the login request it can do when the error appears

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.