3

I can't seem to find anything about setting up connection pooling in WordPress / PHP. Is this possible, and can someone provide some info on how to do it?

I did find some docs on editing wp-db.php and changing MySQL_connect to use mysql_pconnect by that seems hacky (and isn't really connection pooling). I found that the MySQL drivers support putting a "Pooling=True;" parameter in the connection string, but I don't see a way to do this in WordPress.

Any ideas?

  • why would you need connection pooling at all? – Mark Kaplun Mar 3 '17 at 8:42
  • Because the cost of instantiating and destroying database connections over and over again is substantial, especially if the WordPress and MySQL instances are on separate machines and the network is involved. – Craig Mar 30 '17 at 23:24
2

If you just add p: then it conflicts with MySQL Port.

So wp-config.php file you should be able to do it by replacing

define('DB_HOST','localhost');

with

define('DB_HOST','p:localhost:3306');

| improve this answer | |
1

Per the mysqli documentation for opening connections http://php.net/manual/en/mysqli.construct.php, it seems that all you need to do is add p: befor the host name argument, so basically in you wp-config.php file you should be able to do it by replacing

define('DB_HOST','localhost');

with

define('DB_HOST','p:localhost');

| improve this answer | |
  • no joy, it just tells me that the server p:servername is offline or unavailable. :( – mrdenny Mar 15 '17 at 20:17
  • well, documentation seems simple might be worth checking that your specific setup supports it in the mysql driver level – Mark Kaplun Mar 15 '17 at 20:27
  • obviously the other option is that wordpress somehow kills this option, but I didn't see anything in the code that might do that – Mark Kaplun Mar 15 '17 at 20:30

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.