Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:29:51+00:00 2026-06-11T10:29:51+00:00

I inherited a web application written in PHP that uses PostgresSQL as a database

  • 0

I inherited a web application written in PHP that uses PostgresSQL as a database server.
I have no experience whatsoever with PHP and PostgresSQL, I come from a Java / C# background.
I’m studying how it works and while I was profiling it I noticed that the old programmer, during every page request, instantiate a class named Database in which he opens a connection to the database using something like this:

$this->connection = pg_connect($qs, PGSQL_CONNECT_FORCE_NEW)

the profiler tells me this is a very expensive call (the page loads in 2.7 seconds…) and I was wondering if and when the flag PGSQL_CONNECT_FORCE_NEW is actually needed. Since the connection string is always the same I tried to use pg_pconnect instead (or even pg_connect without that flag) and the page loaded in just 741 milliseconds.
Everything seems to work just fine right now but I’m kind of worried this could break the application somewhere, and since I’m not experienced in PHP I would like to know if the practice of using that flags could have a sense in a certain scenario that I need to check. Obviously, there are no unit tests to rely on.
As a side note, do you know good resources about how this pg_(p)connect really works? The official documentation doesnt seem to be deep enough.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:29:53+00:00Added an answer on June 11, 2026 at 10:29 am

    Warning: pg_pconnect will maintain one connection for the lifetime of each Apache backend, so don’t be surprised if you end up with lots of connections. If they all end up issuing a query at the same time that’ll clog the database server up.

    I’ve never heard of a connection to the database taking 2 seconds though. I can start psql, connect, issue a query and get a response in 0.2s and that’s on my old netbook. Check your networking setup or some such – there’s something odd going on here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited a poorly written web application that seems to have errors when
I have a partly inherited web application in PHP and after poking around with
I have recently inherited a J2EE Struts web app that was written back in
I've inherited a web application written in ASP.NET that has an incomplete implementation of
I have inherited a legacy web application that contains API credentials for a Twitter
I have a Web Application that I have inherited it contains a page that
I have inherited an application that uses the ASP.NET membership provider for user management.
I have a web application that I've inherited that has double encoded URLS. If
I've inherited a web application which strictly uses stored procedures to do its job.
I am working on a ASP.Net web forms application which I inherited from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.