• Resolved ikone227

    (@ikone227)


    I am running a PHP script to send emails from a form in a WP page. It works OK when the execution time is not to long, but after a certain duration, I get a “MySQL server has gone away” error, and it seems to be linked to a query initiated by WordFence (see the stack trace below). Apparently, it occurs at the end of the process when the script writes the e-mailing data into a MySQL db, outside WordPress. I don’t understand why Wordfence is involved at this point…

    Can anybody help, please ?

    Thanks,

    Olivier

    Error stack trace :

    0 my_wordpress_directory_path/wp-includes/class-wpdb.php(2349): mysqli_query(Object(mysqli), 'SELECT name, va…')
    #1 my_wordpress_directory_path/wp-includes/class-wpdb.php(2263): wpdb->_do_query('SELECT name, va…')
    #2 my_wordpress_directory_path/wp-includes/class-wpdb.php(3146): wpdb->query('SELECT name, va…')
    #3 my_wordpress_directory_path/wp-content/plugins/wordfence/lib/wfConfig.php(297): wpdb->get_results('SELECT name, va…')
    #4 my_wordpress_directory_path/wp-content/plugins/wordfence/lib/wfConfig.php(375): wfConfig::loadAllOptions()
    #5 my_wordpress_directory_path/wp-content/plugins/wordfence/lib/wfConfig.php(538): wfConfig::hasCachedOption('liveTrafficEnab…')
    #6 my_wordpress_directory_path/wp-content/plugins/wordfence/lib/wfConfig.php(932): wfConfig::get('liveTrafficEnab…')
    # in my_wordpress_directory_path/wp-includes/class-wpdb.php on line 2349

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support wfpeter

    (@wfpeter)

    Hi @ikone227, thanks for reaching out.

    Wordfence, if optimized, will likely still be checking for blockable activity even with your custom script because the auto_prepend_file directive set during optimization means that Wordfence runs after PHP loads but before WordPress or other content is served to the browser. The “liveTrafficEnab…” part seems to suggest Wordfence would be looking to write the activity happening to your Live Traffic page depending on your settings, or whether there’s something security-related to report.

    Generally speaking, the MySQL server has gone away error is something we’ve seen reported before but is a symptom of the database server restarting/crashing and starting up again automatically.

    Running out of memory can be a cause for this happening. If the database server is crashing or running out of memory, your server admin or host should be able to diagnose and resolve the problem for you by looking at the server logs. This can be a problem with sites on shared servers where another site is to blame for the loss of memory, affecting yours – but is not limited to that kind of setup.

    We would still be happy to look into this a little closer should we need to, but ruling out the database’s availability being the problem would be my first step.

    Let us know what you find out!
    Peter.

    Thread Starter ikone227

    (@ikone227)

    Hi @wfpeter,

    Thank you for your advice.

    I solved the problem by switching to an Ajax call instead of posting a form. Before, the form containing the email adresses was pointing to a php file sending the mails AND displaying the results in the browser. It appears that when the sendings were too long (about 2 minutes) the connection with the browser was lost.

    Now I am sending the form data via Ajax, returns the results in the browser and displays them with javascript.

    Best regards,

    Olivier

    Plugin Support wfpeter

    (@wfpeter)

    Perfect, great solution and thanks for letting us know @ikone227!

    If you need Wordfence assistance in future by all means start up a new topic and we’ll be glad to help out any time.

    Peter.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘“MySQL server has gone away” on WF query’ is closed to new replies.