CartMetrix - Do you know yours?

4/10/2007

Lsof Tricks

Lsof (LiSt Open Files) is a powerful Unix command utility that comes in handy in many security and performance related sysadmin tasks.

List the PIDs of running httpd processes. The -t option specifies terse output, only PIDs.

lsof -t `which httpd`

List process listening to port 80.

lsof -i : 80

List processes of the specified command (-c). Search is implied in this usage. It essentially searches for any process name starting with the specified value. The second example would list all process starting with m, (mysqld, mutt, etc.)

lsof -c httpd
lsof -c m

Find processes owned by users apache or nobody.

lsof -u apache,nobody

Find the files using the process specified by PID

.

lsof +p <pid>

Find processes with files open in the directory specified.

lsof +D /tmp

Popularity: 16%

4/9/2007

Wordpress Hack to Debug Themes on a Live Site

How can a Wordpress them be debugged privately without showing the wizard behind the curtain to everyone else? This simple hack will use the specified theme only for one remote IP... yours. This can be used when creating a new theme by configuring Wordpress to present the original theme and specifying your new theme in development in place of THEME_NAME below. Also replace YOUR_IP_ADDR with your local IP address. THEME_NAME must be an existing theme directory in wp-content/themes/.

To debug an existing theme, copy your theme directory to a new directory under /themes/ (maybe THEME_NAME-dev). Leave Wordpress configured to serve the original theme at THEME_NAME and configure the hack to serve THEME_NAME-dev to your IP address.

Edit wordpress/wp-includes/theme.php as below:

Before

function get_template() {
   return apply_filters('template', get_option('template'));
}

After

function get_template() {
if($_SERVER['REMOTE_ADDR'] == 'YOUR_IP_ADDR')   {
   return 'THEME_NAME';
}
   return apply_filters('template', get_option('template'));
}

Depending on how the template links to it's stylesheet, the get_stylesheet() function (in the same file) may need a similar hack:

Before

function get_stylesheet() {
   return apply_filters('stylesheet', get_option('stylesheet'));
}

After

function get_stylesheet() {
if($_SERVER['REMOTE_ADDR'] == 'YOUR_IP_ADDR')   {
   return 'THEME_NAME';
}
   return apply_filters('stylesheet', get_option('stylesheet'));
}

This will not work with a private IP address like 192.168.x.x or 10.10.x.x. The IP must be the external address of your router or firewall. To find your external IP address use this link:
http://emailurl.com/myip

Also remember that if you change local IP addresses, you need to update the IP address configured in the snippet above. Most DSL/cable connections use a dynamic IP address that changes every few hours or daily.

Once the theme is good to go, merge the changes into the live template and comment out the code to disable the hack.

Popularity: 25%

4/5/2007

Easy MySQL Sorting Mistake

If you have a compound ORDER BY clause with a direction (ASC or DESC), make sure to specify the directions of all columns.

Correct:

ORDER BY col1 DESC, col2 DESC

Wrong:

ORDER BY col1, col2 DESC

The latter forces a filesort.

Popularity: 13%


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2008 damonparker.org. all rights reserved.

Close
E-mail It