Computing

Information technology.

Memory leaks caused by PHP are hard to pinpoint. My server started crashing regularly, out of memory from running WordPress on Apache22 and FreeBSD. It happens especially when posting, but also at random times. I tried disabling plugins, changing the theme, to no avail. There might be more than one faulty script, and there is little hope to find these leaks. Hopefully they will be plugged in future releases. In the mean time, I wrote a Python script that checks memory status and restarts Apache if needed. Placed on a cron job, it runs every ten minutes on my server.:

It is a temporary fix, but it works. Her is my /etc/crontab line:
*/0 * * * * root /usr/local/bin/python /home/gil/scripts/mleaks.py

Good luck!

It doesn’t take more than one directory on your web server with write permissions to let someone in.. I started to notice Perl processes running under the www user on my server. It was taking a lot of the CPU, and I couldn’t find the culprit. The only thing I could do was shutting down the Apache web server, then killing the www processes: kill -9 -uwww. But then, it would restart later. So, I looked in the most likely directory /tmp for suspicious files. There were… Perl scripts disguised as images or txt files. It was an Indonesian IRC bot. I removed the files, wondering how they got into /tmp.

The next day, the offending processes resumed! There had to be some other malicious Perl script somewhere. I did a grep -R /usr/bin/perl /home. To locate all files chmoded 777, I tried find /home -type d -perm 777. One of my users was running OSCommerce, and had the images directory chmoded to 777. Ha! The directory was full of exploit files owned by the www user. I deleted them and chmoded the directory to 755. Hopefully that will be the end of it. I will keep a close eye on server processes and any new files owned by www, or containing Perl code.

Any suggestion would be appreciated on how to avoid future problems. I strongly encourage anyone managing a server to check their permissions, and look for Perl scripts that shouldn’t be there.

I don’t do Windows. By that, I mean that I stay clear of any Windows operating system run computer by at least twenty feet! I don’t have a MAC, nothing against them… I use Ubuntu Linux on both my desktop and laptop. So, no iTunes for me. I wish Apple would get it’s act together and compile a Linux version. I’m not holding my breath…

My girlfriend got me an iPod touch this last Christmas, and I love it. Problem is, I can’t transfer files to it without iTunes. Well, until tonight!

It turns out that all you have to do is to get “FTP Server by SavySoda.” This free app turns your iPod into an FTP server. You need an FTP client on your computer. I use FileZilla (there is a Windows version). Upon starting the app, you need to click the ON button. The program then shows you the iPod IP address and port number to connect to. User is “Anonymous,” no password. I had to click it ON/OFF a few times to finally get the IP/Port info to show-up, but then it worked great. The files go into some directory reserved for the app. I have not yet found a way to move them to the regular “Videos” app. Movies do play just fine however, and that’s all I needed.

You won’t want to use this on a public wireless network, since there is no password protection, even if you have one set on your iPod. Don’t forget to turn the server OFF when you’re finished!

Good luck!

I have my aviation site Planenews on a FreeBSD server. As traffic increased, I was getting more database errors. Looking around the web for clues, I discovered that FreeBSD did not have a default my.cnf file in /usr/local/etc. You can find sample files in /usr/local/share/mysql. I used my-huge.cnf, renamed it to my.cnf, put it in /usr/local/etc, et voila (don’t forget to restart MySQL)!

Problem solved? Nope.. I was still getting errors at peak traffic. I then found mysqltuner, a Perl diagnosis tool for MySQL. I was missing a few variables in my.cnf. See the file below, and notice the additions under “Added by Gil.”


# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 128M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4

# Added b Gil:
# max_connections 250 crashes my server, use with caution..
#max_connections = 250
wait_timeout = 180
interactive_timeout = 45
tmp_table_size = 64M
max_heap_table_size = 32M


# Disable Federated by default
skip-federated
skip-innodb
skip-bdb

# Replication Master Server (default)
# binary logging is required for replication
#log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id       = 1

# Point the following paths to different dedicated disks
#tmpdir         = /tmp/
#log-update     = /path-to-dedicated-directory/hostname

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

The site seems to be running fine now, with no errors. I guess I will have to wait for a story to make it to a major social networking site to see if it really can take a heavy load. Please tell me about your optimization tips, and how you prepared for traffic spikes…

I just discovered the Pretty Link WordPress plugin, and I think it will help getting more returning visitors to my site, especially using the Pretty Bar feature. Problem is, I have 11,000 posts, with almost as many links. So, I wrote a Python Script to convert all your old post links to Pretty Links. You need to insert your database login on lines 23,24,25,26. Replace ‘planenews’ on line 49 by your site name, without the .com. Replace my domain by yours on line 58. If you leave line 69 as it, the script will set your Pretty Links to show with the Pretty Bar, standard parameter forwarding, group 1, traking on. If it works for you, you better send me a few bucks to buy a Cigar or a Cointreau, because this will save you a lot of time! (Click on the Donate button below), Scroll down to get the code…






Update: You may have to run it a few times until the script returns no result.. No time to figure out why.. Make sure you backup your database before playing with this!