3

Can someone help me with this error?

[08-Apr-2013 17:44:08 Europe/Berlin] PHP Warning:  PDO::__construct(): [2002]
    Cannot assign requested address (trying to connect via tcp://****:3306) in 
    /var/www/***
[08-Apr-2013 17:44:08 Europe/Berlin] PHP Fatal error:  Uncaught exception 
    'PDOException' with message 'SQLSTATE[HY000] [2002] Cannot assign requested 
    address' in /var/www/***

I have a Server with a lot connections per second; out of about 100 Connections, a single one got this error.

I've tried this recommendation from stackoverflow however it does not solve my problem.

1
2

You could also be hitting max open files (sockets) under Linux. You can change this in /etc/security/limits.conf.

2

Using a persistent connection worked for me. The linked recommondation above shows how to create a persistent connection with mysqli. I am using PDO, too. So I had to add the following to my connection-call:

$mysql = new PDO(
    "mysql:host=$mySqlServer;dbname=$mySqlDatabase;charset=utf8",
    $mySqlUser,
    $mySqlPassword,
    array(PDO::ATTR_PERSISTENT => true));

More information and possible limitations can be found here: http://php.net/manual/de/pdo.connections.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.