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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:27:06+00:00 2026-05-27T10:27:06+00:00

I get the following error: Link to server lost, unable to reconnect I have

  • 0

I get the following error:

Link to server lost, unable to reconnect

I have a mysql daemon coded, and I use mysql_pconnect to connect to mysql but after a while, I get the following error and the daemon stops functioning properly:

Link to server lost, unable to reconnect

What I do is the following:

while(true)
{
  $connect = mysql_pconnect(...);
  $db = mysql_select_db(...);
}

What can I do to prevent this? I need mysql connection to stay steady for the whole duration of the daemon – which may be forever.

  • 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-05-27T10:27:06+00:00Added an answer on May 27, 2026 at 10:27 am

    You have a few choices.

    But just as a precursor, you should try and move away from relying on mysql_* and start using the PDO instead.

    Anyway…
    When you open a mysql connection, it will stay “available” until the wait timeout has expired. What you are doing is constantly creating a new connection, (also without closing the other connection). This means you will either hit the server mysql limit, or your unix box socket limit very quickly.

    Wait Timeout

    You should first check with your server to see what this timeout is set to.
    You might want to consider increasing it in your my.cnf if it is terribly low. The default period is 28800 seconds (if I recall correctly).

    You can check by issuing this query:

    SHOW variables like "%wait_timeout%"
    

    You can then change the value in your my.cnf to increase it or you can also set it using

    SET @@GLOBAL.wait_timeout=288000
    

    SELECT 1

    Okay, now, with a reasonable set timeout set, the “typical” way that you can make sure that you don’t get the mysql has gone away message, is to just do a SELECT 1. This will do another query and make sure that the connection is held open.

    And, the benefit of using the PDO is that you can then catch PDOExceptions which might be thrown when a SELECT 1 fails.

    This means, that you can then try and connect again, if an exception is thrown, and then check again. If you can’t connect after that then you should probably kill your daemon.
    Here is some code…. you would clearly have to make your PDO object using a valid connection string.

        // $pdo holds the connection and a PDO object.  
        try {
                $pdo->execute("SELECT 1");
            } catch (PDOException $e) {
                // Mysql has gone away. 
                $pdo = null
                $pdo = new PDO( $connectionString );
                echo "Mysql has gone away - But we attempted to reconnect\n";
                try {
                     $pdo->execute("SELECT 1");
                } catch (PDOException $e) {
                     echo "Mysql has failed twice - Kill Daemon\n";
                     throw($e);
                }
          }
    

    This is the solution that I would probably take.

    You can easily substitute the SELECT 1 with your own query that you actually want to use. This is just an example.

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

Sidebar

Related Questions

When I start the server, I get the following error [Error: Unable to load
I get following error when deploying on test server with II6 and Framework 3.5
I get the following error: Client does not support authentication protocol requested by server;
I get the following error when attempting to connect to a web service via
I get the following error when inserting data from mysql into postgres. Do I
On my local server, I'm getting the following error in terminal [03/Oct/2011 22:49:19] GET
I get following error when trying to access Xampp from a network I've tried
I get following error: 2012-04-04 23:46:18.374 istiqlaltv[17121:e903] -[istiqlaltvViewController moviePlayBackDidFinish]: unrecognized selector sent to instance
I am using the code as described in this question. However get following error
I get the following error: Unhandled Exception: System.IO.IOException: The parameter is incorrect. at System.IO.__Error.WinIOError(Int32

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.