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 8942555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:32:35+00:00 2026-06-15T11:32:35+00:00

PHP has some persistent version of well-known functions such as mysql_pconnect (deprecated) or pfsockopen

  • 0

PHP has some persistent version of well-known functions such as mysql_pconnect (deprecated) or pfsockopen

From what I’ve read, I understand that such functions cache the resource produced by the first call and reused when needed.

  • But for exemple with pfsockopen what happen to the socket when it’s
    cached ?
  • is it still open and connected ?
  • If so , what happen to the potential data received during the
    “sleep” time ?
  • What is the TTL of such cached connection ?

Long story short , how does all the “p” functions really works in background ? The official doc about all this is close to nil

  • 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-15T11:32:36+00:00Added an answer on June 15, 2026 at 11:32 am

    The resource in question isn’t really cached, not in the true meaning of cache that is. The connections are just kept open until the script terminates or until you call the appropriate function that closes it (so don’t call e.g. mysql_close() if you want to use a persistent connection).

    Now, the real question is – what does “until the script is terminated” mean. This may vary or may not be possible, depending on the PHP SAPI that’s currently used, but let’s take Apache with support for HTTP/1.1 + mod_php as an example – it’s the most popular and easiest to explain …

    HTTP/1.1 is required, because it has Keep-Alive – something rather strange for a stateless protocol. When you access a page, Apache runs your PHP script under a thread or a new system process.
    And here’s the catch – your script does execute in it’s entirety, but Apache does NOT terminate the thread or process in question, allowing it to maintain persistency for resources that are left open. How exactly it’s done I’m not sure I can explain, but with Keep-Alive your next HTTP request will be attached by Apache to the same thread or process id, allowing possibility to reuse that resource.
    The second part is more of just a basic sanity check – you can only attach to a persistent connection if you’re using the same “options” and/or credentials that you’ve used to create it. So if you call mysql_connect() with a different username – it will create a new connection and won’t reuse the old one (it’s signature doesn’t match). But given that supposedly the same script is re-executed, this is only a “fomality” in most cases.

    I hope that makes sense to you, it took me a few hours of experimenting in order to fully understand how it works. You can read more about it on php.net – the article is named “Persistent Database Connections”, but that’s only because originally persistent connections were only available for databases – the described behavior is true for all other equivalents.

    Edit:

    Forgot to answer your more specific questions:

    • But for exemple with pfsockopen what happen to the socket when it’s cached ?

      Nothing – it’s just kept alive, as already explained above.

    • Is it still open and connected ?

      Yes

    • If so , what happen to the potential data received during the “sleep” time ?

      It waits for you to read it.

    • What is the TTL of such cached connection ?

      That in particular I can’t answer – it may depend on the options that you pass to the p* function, your php.ini settings and/or what you’re connecting to. It may also be a hard-coded value and to be different for all of them.

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

Sidebar

Related Questions

PHP has some pretty inconsistent parameters for functions (e.g. sometimes first haystack , then
PHP has some great functions (like array_walk) that allow you to process each element
I have a php file which has some variables like $name1, $name2... How can
I am working on a PHP-Mysql based website which has some large lists to
A long shot but here's hoping someone has some experience coding PHP hooks for
PHP 5.3 has been released some time ago and the developers tried to keep
I am developing an app in PHP and at some points the app has
Explanation PHP has some holes in its' syntax and occasionally in development a programmer
I am coding a web application in PHP and it has some performance intensive
37signals has some popular online web apps. There are some free alternatives (mostly PHP)

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.