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

  • Home
  • SEARCH
  • 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 8684517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:19:46+00:00 2026-06-12T22:19:46+00:00

I have a problem with MySQL timeouts in my 24/7 PHP shell script. I

  • 0

I have a problem with MySQL timeouts in my 24/7 PHP shell script.

I was under impression that Pear DB DB::connect() would create new handle but this does not seem to be the case. DB::connect() actually returns “server has gone away” error even when used in a loop for five times.

I now added db->disconnect() and unset( $db) to the script before the DB::connect(). Will this cause the underlying mysql module to free the resources before connect (localhost) ? If not then I don’t see other options than using the proprietary new_link.

  • 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-12T22:19:47+00:00Added an answer on June 12, 2026 at 10:19 pm

    Hmm. Inconclusive.

    I made sample php script to connect twice with same settings, run mysql_close() and then third connection.
    I also ran tcpdump in another window.

    On the first few runs there was some traffic to the server on subsequent connects. Then this traffic disappeared.

    Now the result is that without mysql_close() the mysql_connect() indeed uses the previous connection and there is zero traffic on subsequent mysql_connect().

    When running mysql_close() the dump would indicate the TCP connection is closed.

    On the third connect the connection is again established from the start.

    13:37:57.842598 IP 192.168.1.1.58772 > 192.168.2.2.mysql: S 3281731243:3281731243(0) win 5840 <mss 1460,sackOK,timestamp 503312235 0,nop,wscale 7>
    13:37:57.887534 IP 192.168.2.2.mysql > 192.168.1.1.58772: S 1293434507:1293434507(0) ack 3281731244 win 5792 <mss 1460,sackOK,timestamp 3402066848 503312235,nop,wscale 7>
    13:37:57.887639 IP 192.168.1.1.58772 > 192.168.2.2.mysql: . ack 1 win 46 <nop,nop,timestamp 503312245 3402066848>
    13:37:57.932750 IP 192.168.2.2.mysql > 192.168.1.1.58772: P 1:61(60) ack 1 win 46 <nop,nop,timestamp 3402066859 503312245>
    13:37:57.932843 IP 192.168.1.1.58772 > 192.168.2.2.mysql: . ack 61 win 46 <nop,nop,timestamp 503312256 3402066859>
    13:37:57.935983 IP 192.168.1.1.58772 > 192.168.2.2.mysql: P 1:62(61) ack 61 win 46 <nop,nop,timestamp 503312258 3402066859>
    13:37:57.981130 IP 192.168.2.2.mysql > 192.168.1.1.58772: . ack 62 win 46 <nop,nop,timestamp 3402066871 503312258>
    13:37:57.981181 IP 192.168.2.2.mysql > 192.168.1.1.58772: P 61:72(11) ack 62 win 46 <nop,nop,timestamp 3402066871 503312258>
    13:37:58.017172 IP 192.168.1.1.58772 > 192.168.2.2.mysql: . ack 72 win 46 <nop,nop,timestamp 503312279 3402066871>
    
    at 13:38:01 there was the second mysql connection
    
    at 13:38:04 now the mysql_close():    
    13:38:03.989796 IP 192.168.1.1.58772 > 192.168.2.2.mysql: P 62:67(5) ack 72 win 46 <nop,nop,timestamp 503313772 3402066871>
    13:38:03.989844 IP 192.168.1.1.58772 > 192.168.2.2.mysql: F 67:67(0) ack 72 win 46 <nop,nop,timestamp 503313772 3402066871>
    13:38:04.034818 IP 192.168.2.2.mysql > 192.168.1.1.58772: F 72:72(0) ack 68 win 46 <nop,nop,timestamp 3402068385 503313772>
    13:38:04.034920 IP 192.168.1.1.58772 > 192.168.2.2.mysql: . ack 73 win 46 <nop,nop,timestamp 503313783 3402068385>
    
    at 13:38:07 the third connection after mysql_close(). Afterwards script exits and mysql connection is closed.
    13:38:06.995120 IP 192.168.1.1.58773 > 192.168.2.2.mysql: S 3287179963:3287179963(0) win 5840 <mss 1460,sackOK,timestamp 503314523 0,nop,wscale 7>
    13:38:07.035065 IP 192.168.2.2.mysql > 192.168.1.1.58773: S 1439831970:1439831970(0) ack 3287179964 win 5792 <mss 1460,sackOK,timestamp 3402069136 503314523,nop,wscale 7>
    13:38:07.035166 IP 192.168.1.1.58773 > 192.168.2.2.mysql: . ack 1 win 46 <nop,nop,timestamp 503314533 3402069136>
    13:38:07.075107 IP 192.168.2.2.mysql > 192.168.1.1.58773: P 1:61(60) ack 1 win 46 <nop,nop,timestamp 3402069146 503314533>
    13:38:07.075188 IP 192.168.1.1.58773 > 192.168.2.2.mysql: . ack 61 win 46 <nop,nop,timestamp 503314543 3402069146>
    13:38:07.075437 IP 192.168.1.1.58773 > 192.168.2.2.mysql: P 1:62(61) ack 61 win 46 <nop,nop,timestamp 503314543 3402069146>
    13:38:07.115123 IP 192.168.2.2.mysql > 192.168.1.1.58773: . ack 62 win 46 <nop,nop,timestamp 3402069156 503314543>
    13:38:07.115178 IP 192.168.2.2.mysql > 192.168.1.1.58773: P 61:72(11) ack 62 win 46 <nop,nop,timestamp 3402069156 503314543>
    13:38:07.115821 IP 192.168.1.1.58773 > 192.168.2.2.mysql: P 62:67(5) ack 72 win 46 <nop,nop,timestamp 503314553 3402069156>
    13:38:07.115844 IP 192.168.1.1.58773 > 192.168.2.2.mysql: F 67:67(0) ack 72 win 46 <nop,nop,timestamp 503314553 3402069156>
    13:38:07.155524 IP 192.168.2.2.mysql > 192.168.1.1.58773: F 72:72(0) ack 68 win 46 <nop,nop,timestamp 3402069166 503314553>
    13:38:07.155606 IP 192.168.1.1.58773 > 192.168.2.2.mysql: . ack 73 win 46 <nop,nop,timestamp 503314563 3402069166>
    

    And the script:

    <?php
    
    output( "starting");
    $start = microtime(true);
    $res = mysql_connect('192.168.2.2','user','pass');
    if( $res === FALSE )
            die(output("SQL error on connect\n"));
    output(sprintf("Connect took: %.3f", (microtime(true)-$start)));
    
    output("sleep 3");
    sleep(3);
    
    $start = microtime(true);
    $res = mysql_connect('192.168.2.2','user','pass');
    if( $res === FALSE )
            die(output("SQL error on connect\n"));
    output(sprintf("Connect took: %.3f", (microtime(true)-$start)));
    
    output("sleep 3");
    sleep(3);
    
    output("closing");
    mysql_close( $res );
    
    output("sleep 3");
    sleep(3);
    
    $start = microtime(true);
    $res = mysql_connect('192.168.2.2','user','pass');
    if( $res === FALSE )
            die(output("SQL error on connect\n"));
    output(sprintf("Connect took: %.3f", (microtime(true)-$start)));
    
    output("all done");
    exit;
    
    function output($str)
    {
            echo date('Y-m-d H:i:s')." ".$str."\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with mysql connection. I have a php script which upload
I have some problem with MySQL Workbench in that I sometimes can't set foreign
I have problem with my MySQL query: include '../inc/mysql_config.php'; $sql=INSERT INTO ordrar (id, order,
I have some jsp pages that connect to a mysql database and I intermittently
I have an application that uses Hibernate to connect to my MySQL database. I'm
I have a problem in mySQL that goes as follows: Count the instances of
I have a php / mysql / jquery web app that makes 13 ajax
I have a problem with MySql.Data in a partial trusted environment. I've added MySql.Data
I have a problem in mysql. I need to fetch certain sets of records
I have a mysql problem, my query looks as follows but not complete SELECT

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.