5

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?

2
  • why would you need connection pooling at all? Mar 3, 2017 at 8:42
  • 1
    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. Mar 30, 2017 at 23:24

2 Answers 2

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');

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');

3
  • no joy, it just tells me that the server p:servername is offline or unavailable. :(
    – mrdenny
    Mar 15, 2017 at 20:17
  • well, documentation seems simple might be worth checking that your specific setup supports it in the mysql driver level Mar 15, 2017 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 Mar 15, 2017 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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