Archive for May, 2007

How to keep a MySQL connection alive

Ok, so I wasted about 3 hours on this, and have only sort of found a solution. I have a PHP script which is going to be running 24/7 checking a message queue and then interacting with a database when a message is received. It was mostly working, until it sat there for a day and I tried to use it the next day. The PHP script had quit, with the error “MySQL server has gone away.” I figured there must be some sort of time limit that the mysql server will keep an idle connection alive. I couldn’t find it, but luckily I was talking to nick, and he did! He found this blog entry. So I changed the my.cnf file to set the timeout to one week:

wait_timeout=604800
interactive_timeout=604800

That’ll do for now. The other alternative would be to check if the connection is alive before running a query, and connecting if it isn’t. I couldn’t get that one to work, though.

No Comments

simple guide to creating a RAM disk

I had a thought of using a RAM disk as a message queue for a messaging application I am working on, as opposed to creating a table in a database, or using a regular flat text file. Every time I need a message to be sent, I’ll add a text file on the RAM disk, then the sending process can scan for files. All of this is happening in RAM, so it won’t be thrashing the disk!

Here is a guide I found which was very straightforward. I got the disk set up in a few minutes.
http://www.vanemery.com/Linux/Ramdisk/ramdisk.html

I didn’t bother changing the size of my disks, and it turns out they defaulted to 16mb anyway.

This can be added to a shell script and set to run on startup by calling it in /etc/rc.local

/sbin/mke2fs -q -m 0 /dev/ram0
/bin/mount /dev/ram0 /mnt/rd
/bin/chown van:root /mnt/rd
/bin/chmod 0750 /mnt/rd

1 Comment