PHP, MySQL and error “2006: MySQL server has gone away”

As a hobby I like to do little photography.

Same time I do not like to give my photos to someone else to host, so I have my gallery.

It runs on Menalto’s Gallery 3 engine – nice, open source, PHP based with MySQL back-end.

Not my primary programming language, but allows me to host and enhance my blog, keep my gallery and small web-site.

Last night, while bringing some old photos over from my backup gallery (G3 is still under development and I do not want to recreate gallery if anything to happen, and it did – I killed the setup…), I noticed that import process start to fail. Several attempts to recover did not give much of the progress and I went digging error logs.

Well,.. I learned something interesting. I am not a PHP programmer, at least it is not that I do for living, or not at this time… but even doing simple house work forces you learn things 🙂
G3 runs on Kohana framework and there is a wrapper for DB access.

What happend was that some of the SQL requests began timing out

Database_Exception [ 44 ]: #2006: MySQL server has gone away

In case when queries are not optimal, one has to learn how to manage PHP… through php.ini…

MySQL timeout related errors are “fixed” by telling mysql to reconnect… and for that “tricks” are handy…
From browsing, reading, browsing, filtering, … while waiting for G2 Import I have found a solution which lead me here. One of interest is called mysqli.reconnect. Little magic – simply adding the following line in PHP.INI would tell MySQL reconnect.

mysqli.reconnect=1

It may be still slow, but at least connection would recover gracefully.

We can talk about code styles, code protection and error handling, but line above is a hidden gold on the end of the rainbow called PHP.

This entry was posted in Web-design and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

  • About

    From being a junior developer all the way to Development Manager position, I was always interested in new technologies. Passionate speaker, IT junky, developer, architect, team lead, and development manager - many hats, one goal - making software better and closer to people’s needs. For the most part I am using my blog as a scratch pad, writing small articles on things which I came across, was asked about more then once, and which would otherwise require additional research again and again.

    View Serguei Dosyukov's profile on LinkedIn
  • Testimonials

    I've been using this [theme] since the start. It is by far the most attractive, feature packed and stable of...

    Rhyull

    I’m a huge fan of this theme. I’ve got more than 90,000 pictures in my gallery3 running on a Ubuntu...

    Jklobo

    The greydragon theme is fantastic. It’s clean, stable and feature rich. It took me a while to decide to move...

    Ed

    more...

  • Categories