"MySQL server went away" after using mail()

I have a php script that gets called frequently that runs a short database query and sends an email. The database code uses procedural-style mysql functions such as mysql_query(), etc. The email is sent using the mail() function.

99% of the time it ran without problem. However, sometimes I would get a "MySQL server has gone away" error. The original order of execution was to first send the mail with mail(), and then run the short update query. I switched the order of execution to run the query first and call mail() last, and now I never have a problem.

The problem: mail() somehow interferes with the database connection occasionally. Anybody have any ideas why? How should go about looking for the problem?

More info:

Once the mail script gives the "server went away" error, the query will always fail with that error if I try to run the script again. However, if I run the exact same query in phpMyAdmin it executes with no problem, and afterwards the mail script will work again.

Also, the script ran for many months without any problems - the "server went away" error just started recently, with no changes to any code or configuration on our part. Additionally, the script ran without problems during an extended period of time where the website was getting more than double the amount of traffic it currently gets, so it was not having any problems during a time when the server was dealing with many more database connections, etc., than it is right now.

PHP version: 5.3.3

MySQL version: 5.0.77-log Source distribution

Database is on a different server than the webserver/php script (not connecting to localhost)

Both the webserver and db server are Red Hat Enterprise Linux Server release 5.6 (Tikanga)

-------------Problems Reply------------

You probably have a too short wait-time setting,
official documentation has covered all the scenario

PS AFAIK, there is no mysql server has went away,
but mysql server has gone away

Category:php Views:1 Time:2011-09-06
Tags: php mysql

Related post

  • What are maintenance steps and performance steps for Mysql server/database? 2010-04-15

    Like index maintenance we have index reorganize/rebuild, update stats, shrink database log files , database backup/restore in MS SQL server, What are maintenance steps and performance steps for Mysql server/database ? --------------Solutions---------

  • Getting check the manual that corresponds to your MySQL server version for the right syntax to use? 2012-01-13

    Going through Lynda's 2010 tutorial on rails and have been stuck on migration for the past couple of days. When running $ rake db:migrate I get NOC-4:app noc$ rake db:migrate (in /Users/noc/rails_projects/app) == CreateUsers: migrating ==============

  • Pylons error - 'MySQL server has gone away' 2008-08-11

    [I hope this isn't too obscure… I'll ask the newsgroup if nobody knows here] I'm using Pylons (a python framework) to serve a simple web application, but it seems to die from time to time, with this in the error log: (2006, 'MySQL server has gone awa

  • Dealing with PHP server and MySQL server in different time zones 2008-08-20

    For those of us who use standard shared hosting packages, such as GoDaddy or Network Solutions, how do you handle datetime conversions when your hosting server (PHP) and MySQL server are in different time zones? Also, does anybody have some best prac

  • What is the best way to communicate with a MySQL server? 2008-08-22

    I am going to be using C/C++, and would like to know the best way to talk to a MySQL server. Should I use the library that comes with the server installation? Are they any good libraries I should consider other than the official one? --------------So

  • How do I enable external access to MySQL Server? 2008-09-10

    How do I enable external access to MySQL Server? I can connect locally but I cannot connect from another box on the network. I just tried grant all privileges on *.* to [email protected]'%' identified by '*****' with grant option; And restarted MySQL Server with

  • mod_python/MySQL error on INSERT with a lot of data: "OperationalError: (2006, 'MySQL server has gone away')" 2008-09-15

    When doing an INSERT with a lot of data, ie~ `INSERT INTO table (mediumtext_field) VALUES ('...lots of text here: about 2MB worth...')', MySQL returns "OperationalError: (2006, 'MySQL server has gone away')" This is happening within a minute of start

  • Can't connect to MySQL server on 'localhost' (10061) 2008-09-23

    I recently installed MySQL 5 on Windows 2003 and tried configuring an instance. Everything worked fine until I got to "Applying Security settings", at which point it gave me the above error (Can't connect to MySQL server on 'localhost' (10061)). I do

  • MySQL server goes away in XAMPP 2008-10-02

    I am trying to install xampp 1.6.7 in a Red Hat Enterprise Edition. I followed the installation instructions and after that I started the stack with the command sudo /opt/lampp/lampp start And I get te usual response XAMPP: Starting Apache with SSL (

  • Connecting phpMyAdmin to a MySQL server over SSL 2008-12-01

    I may be barking up the wrong tree... However, what I have is a MySQL server that accepts connections only from a client with a valid SSL cert (see this link). This works great for example with Rails. I have my database on one server, and a Rails app

  • MYSQL - Cant connect to MYSQL server on 'localhost' (10061) 2008-12-22

    Ive install wamp server on my PC(it has no internet or intranet connection, Windows XP -OS). But when I access MYSQL this error popup. Can you give any idea on how can i resolve this error. thank you very much. Cant connect to MYSQL server on 'localh

  • Connect to a MySQL server over SSH in PHP 2009-01-21

    i read one post regarding this topic, i also want to do the same, i have my database on remote linux machine, and i want to connect using ssh and php funcitons,(i am currently using ssh2 library for that) i tried using mysql_connect, but it gives me

  • What problems can arise if php mysql client doesn't match the mysql server version? 2009-03-18

    I have two installations of mysql server 5.1.32 and 5.0.77 (same machine, os x leopard). My php mysql extension is compiled against 5.0.77 (that was the easiest thing to do, and I did it after installing 5.1.32). I'm using the 5.1.32 installation sin

  • Migrating a MySQL server from one box to another 2009-03-29

    The databases are prohibitively large (> 400MB), so dump > SCP > source is proving to be hours and hours work. Is there an easier way? Can I connect to the DB directly and import from the new server? --------------Solutions------------- You

  • Why can't I connect to my sql database? I get the error message: "Can't connect to local MySQL server through socket" 2009-04-02

    I just moved my site to a new web host, and after changing the database-login file, it still can't connect. I get the following error: Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

  • how to add a port to mysql server 2009-04-26

    I want to add to MySql another tcp port that I can connect to that port from my application I have a duplicate of my application and I'm running them both from the same machine. They both are connected to the MySql server that are running on the same

  • Synchronizing sql mobile data with mysql server 2009-05-13

    We can synchronize the data from SQL mobile with SQL Server. But i need to synchronize the mobile data with mysql server. Is there any way to accomplish my requirement...? --------------Solutions------------- you should check out sync services for ad

  • Access Mysql server using socks proxy from a php script 2009-05-17

    Plain and simple, can anyone explain me how to connect to a mysql server through a proxy (socks4/5). Preferable via the mysql command line (although there are no options for that in the client). If it's not possible through the mysql command line tha

  • Is it possible to create an event and handle it, if the connection to a MySQL server is lost? 2009-06-04

    Let's say I have my client application and it makes a connection to the MySQL server. Fantastic. I don't implement this as a thread. I just utilise the MySQLConnection class. And now let's say Jim who's really careless about the office accidently reb

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.122 (s). 11 q(s)