67

One of the parameters in the CodeIgniter database config is the following

['pconnect'] TRUE/FALSE - Whether to use a persistent connection

What do you recommend I set this to?
Is there a significant performance hit if I set it to FALSE?
What potential problems might arise from setting it to TRUE?

Clayton
  • 6,089
  • 10
  • 44
  • 47

1 Answers1

105

Just look up general best practices for persistent connections. My suggestions.

  • By default, DO NOT
  • If you have:
    • Dedicated web server and database hardware in production
    • and have tuned the web server and database correctly
    • and have an accurate production-like test environment
    • And still think your performance problems are caused by database connection time,

CONSIDER turning it on

Persistent connections can cause

  • Bugs because some connection state persisted unintentionally (this is a biggie!)
  • Database connection limits to be exceeded
  • Database performance to drop because of lots of ram used by the many (mostly idle) connections
  • Bugs because connections have gone "stale" and the app didn't notice

But CAN

  • Reduce latency on initial connection

If you think that connection latency is causing a problem, consider turning it on in your performance test system and measuring the impact.

MarkR
  • 62,604
  • 14
  • 116
  • 151
  • 3
    Great answer brother gives lots of clarity. – Ganatra Jan 28 '14 at 13:37
  • Can I just add that you can use connection pooling but that this ntroduces its own set of issues to adress and I'm not sure that codeigniter can handle them. http://php.net/manual/en/book.mysqlnd-ms.php – David Soussan Mar 16 '15 at 06:02