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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:25:34+00:00 2026-05-24T04:25:34+00:00

My scripts are getting quite riddled with forked processes in a lot of different

  • 0

My scripts are getting quite riddled with forked processes in a lot of different functions. Whenever pcntl_fork() is called, all MySQL connections are lost. If I run a query on a PDO MySQL connection I get the error "MySQL server has gone away".

The problem is that this error only shows up in PDO::errorinfo() after a failed query execution. I would like to be able to detect if the MySQL server “has gone away” before I try to run a query. That way I could create a PDO wrapper that makes a new connection for me in such situations.

Any ideas?

  • 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-24T04:25:35+00:00Added an answer on May 24, 2026 at 4:25 am

    I give you 2 methods by example (similar in some ways) :
    Example 1 :

    $sql = 'SELECT count(*) FROM `TABLE`;';
    for ($i = 1; $i <= 2; $i++) {
        try {
            $nb = $pdo->query($sql)->fetchColumn();
            if (is_int($nb)) {
                // OK
                break;
            }
        } catch (PDOException $e) {
        //Oups
            if ($i == 1) {
                // First time ? retry
                $pdo = new PDO($dsn, $user, $password);
            } else {
                // Second time, KO
                $nb = "(unknown)";
                echo 'PDO Connection failed: ' . $e->getMessage().'. ';
            }
        }
    }
    

    Example 2 :

    // check
    try {
        $pdo->query('select 1;')
        //OK
    } catch (PDOException $e) {
        //Oups => reconnect
        $pdo = new PDO($dsn, $user, $password);
    }
    // Should be good
    $sql = 'SELECT count(*) FROM `TABLE`;';
    $nb = $pdo->query($sql)->fetchColumn();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i already have a post which is quite similiar, but i am getting more
hvaing problems getting datepicker to work, not quite sure why. <link rel=stylesheet href=styles/style.css> <link
I keep on getting this error when running one of my scripts; PHP Fatal
Getting some odd behaviour in a Perl script that I don't quite understand. I'm
I know this is a quite simple script, but I keep getting an error
I'm fairly new to JavaScript so I don't quite understand why I am getting
I'm having a little issue getting quite a simple bash script running. The part
I have a portion of a bash script that is getting a filename without
I'm getting an error message from a python script at position 21490 . How
Getting an error when i use the following script to show a div when

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.