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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:27:51+00:00 2026-06-10T11:27:51+00:00

I have been scratching my head trying to figure out what is causing an

  • 0

I have been scratching my head trying to figure out what is causing an intermittent error in my script. The error is: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away.

My script below is part of a function that does a curl, gets some values from a JSON response, and then writes them to a table. I’d say 80% of the time it works fine and then the other 20% i get the server gone away error. I haven’t been able to identify any trends that causes it to error out, it just seems to be random. Any ideas why i might be getting this error? thanks for checking this out

    ...
    //post via cURL 
    $ch = curl_init( $url );
    $timeout = 500;
    curl_setopt( $ch, CURLOPT_POST, 1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt( $ch, CURLOPT_HEADER, 0);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
    $this->response = curl_exec( $ch );
    $this->json_decoded = json_decode($this->response);
    $this->full = print_r($this->json_decoded, true);
    $client_leadid = $this->json_decoded->Parameters->lead_id;
    $client_status = $this->json_decoded->Status;   
    $length = curl_getinfo($ch);
    curl_close($ch);

    //record in DB
    $insert = $this->full.' | '.$url.' | '.$myvars.' | '.$this->date . ' | Time Taken: '.$length['total_time'];
    $db->exec("UPDATE table SET client_resp = '$insert' WHERE global_id = '$this->leadid' LIMIT 1");
    $db->exec("UPDATE table SET client_leadid = '$client_leadid' WHERE global_id = '$this->leadid' LIMIT 1");
  • 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-10T11:27:53+00:00Added an answer on June 10, 2026 at 11:27 am

    This is probably happening because your CURL request is taking longer then the mysql connection timeout

    either
    1) set a request-timeout for CURL so it dies sooner on errors (CURLOPT_CONNECTTIMEOUT is only for connections- CURLOPT_TIMEOUT is for the overall length of the request and it will stop if the server doesn’t respond in time)
    2) turn up the mysql idle timeouts to prevent the server from disconnecting you for not sending queries
    3) detect the error and automatically reconnect to mysql

    mysql> show variables like "%timeout%";
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | connect_timeout          | 5     |
    | delayed_insert_timeout   | 300   |
    | innodb_lock_wait_timeout | 50    |
    | interactive_timeout      | 28800 |
    | net_read_timeout         | 30    |
    | net_write_timeout        | 60    |
    | slave_net_timeout        | 3600  |
    | table_lock_wait_timeout  | 50    |
    | wait_timeout             | 28800 |
    +--------------------------+-------+
    9 rows in set (0.00 sec)
    

    wait_timeout and interactive_timeout are the two you care about

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

Sidebar

Related Questions

I have been scratching my head for hours trying to figure out why this
I've been scratching my head for hours trying to figure this out. I have
i'v been scratching my head for two hours in trying to figure out whats
I have been scratching my head trying to find any resources on substringing an
I have been scratching my head trying to get Jquery to conditionally search and
I have been scratching my head for a while on this one. I dont
I've been scratching my head over this for an hour... I have a list
I have been scratching my head all morning behind this but still haven't been
I have been scratching my head for the better part of the evening on
I have been scratching my head since long now but not getting around to

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.