Persistent connection to mysql database

Notice: This thread is very old.
vnovotny
Member | 12
+
0
-

Hi,

need some help with persistent connection to Mysql Database. I have some simple crawler and this simple crawler runs dozens of parallel php requests. Therefore I have dozens of parallel mysql connection. Right now I reached max connection limit on my MySQL server hosted by Amazon.

There are two possible solutions:

  1. Rewrite app to have only few permanently running php script accessing DB
  2. Use for this server persistant DB connection.

My question is: Is there any native support in Nette Database for persistent connections? Where should I look first if there is not native implementation?

Edit:

There is support for persistent connections in PDO. My question is, how to make PDO in Nette Database work with this.

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(
    PDO::ATTR_PERSISTENT => true
?>

Edit 2:

I will try this (just to get some new skill :-) And then probably rewrite the app. Thanks Tomáš.

nette:
    database:
        default:
            dsn:        "mysql:host=127.0.0.1;dbname=test"
            user:       "root"
            password:   "password"
            options:    [PDO::ATTR_PERSISTENT = true]

Last edited by vnovotny (2015-01-08 12:44)

Tomáš Kolinger
Member | 136
+
+1
-

Nette Database do not have support for this i think. But PDO does – http://php.net/…nections.php#… – and you can get PDO instance from Nette\Database\Connection so this can be way. Use Connection::options to set that PDO option (https://api.nette.org/…ion.php.html#61).

But PHP is not really good tool for kind of this job. Because PHP not have real multi-threading. Maybe is better to use proper tool instead.

Last edited by Tomáš Kolinger (2015-01-08 12:42)