CartMetrix - Do you know yours?

9/30/2005

Lighttpd Startup Script

The source distribution of Lighttpd does not include a startup script (and if you want something lightweight building from source is the only way to go). I found a Linux init script in the RPM distribution from the Dag repository. You can install the latest RPM from the repository or just pick up the init script below.

Download

With most Linux distributions it can be placed in /etc/init.d/ along with all of the other init scripts.

Popularity: 19%

9/29/2005

Download a Remote File Using PHP

On hosts with safe_mode turned on, it can be difficult to get remote files with a system call to wget or curl. Here is a PHP function that will get a file with an HTTP GET. I use it to download remote images. It returns the binary data in a variable that can be written to a file.

<?php
function http_get_file($url)  {

   $url_stuff = parse_url($url);
   $port = isset($url_stuff['port']) ? $url_stuff['port']:80;

   $fp = fsockopen($url_stuff['host'], $port);

   $query  = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n";
   $query .= 'Host: ' . $url_stuff['host'];
   $query .= "\n\n";

   fwrite($fp, $query);

   while ($line = fread($fp, 1024)) {
      $buffer .= $line;
   }

   preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);
   return substr($buffer, - $parts[1]);
}
?>

Original function found on php.net

Popularity: 41%

Delete Files Newer Than

Delete a files newer than filename in the local directory

find ./ -type f -newer filename -print|xargs rm

Delete a files older (ie. not newer) than filename in the local directory

find ./ -type f ! -newer filename -print|xargs rm

Popularity: 13%

9/27/2005

Lighttpd Update

I have written several times about this Lighttpd install. I had to check something on the server last night so I popped over to the server-stats page to see what kind of throughput it was pushing.

I was a little suprised at the 7MB/s. Thats pretty awesome. A large MP3 every second! 180 million requests and 15 Tera bytes processed without a hiccup isn’t too shabby either.

Hostname: img.xxxxxxx.com ()
Uptime 26 days 20 hours 33 min 21 s
Started at 2005-09-01 00:03:07
absolute (since start)
Requests 180 Mreq
Traffic 14 Tbyte
average (5s sliding average)
Requests 98 req/s
Traffic 7 Mbyte/s
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
5731 nobody 20 4 76132 73M 736 S N 1.1 1.8 1904:01 2 lighttpd
622 nobody 19 4 11372 11M 6264 S N 0.5 0.2 0:10 2 httpd
1714 nobody 19 4 11968 11M 5904 S N 0.5 0.2 0:09 1 httpd
627 nobody 19 4 11236 10M 5968 S N 0.4 0.2 0:12 1 httpd
5498 nobody 19 4 9504 9504 5468 S N 0.4 0.2 0:03 0 httpd
1857 nobody 19 4 10668 10M 6072 S N 0.3 0.2 0:07 1 httpd
4291 nobody 20 4 10472 10M 5836 S N 0.3 0.2 0:04 2 httpd
5481 nobody 19 4 10220 9M 5404 S N 0.3 0.2 0:02 2 httpd
5494 nobody 20 4 10924 10M 6380 S N 0.3 0.2 0:03 0 httpd
1721 nobody 19 4 10756 10M 5988 S N 0.2 0.2 0:09 3 httpd
1863 nobody 19 4 10816 10M 6100 S N 0.2 0.2 0:09 1 httpd
5478 nobody 19 4 10396 10M 5804 S N 0.2 0.2 0:03 0 httpd
1725 nobody 19 4 11488 11M 6428 S N 0.1 0.2 0:10 2 httpd
2544 nobody 19 4 10564 10M 5784 S N 0.1 0.2 0:07 2 httpd
5486 nobody 19 4 10032 9.8M 5724 S N 0.1 0.2 0:03 2 httpd

Popularity: 19%

The Other Costs of Hurricane Rita

The devastation caused by Hurricane Katrina was horrible. It was actually caused by a worthy adversary… a real storm. I have seen some of real devastation of Hurricane Rita, and I am in no way belittling the real, physical losses sustained in East Texas and Western Lousianna. BUT, a large percentage of the monetary loss and loss of life is a direct result of the unnecessary evacuations.

The ‘mandatory’ evacuations of cities and counties in all up and down the Texas Gulf Coast four days before landfall or even a halfway accurate projected landfall location has caused millions of dollars in lost business revenues, wages, wasted fuel costs and state and local infrastructure expenditures. The unwarranted mass evactuations from as far away as Corpus Christi, wasted hotel rooms that should have been available those that really might have been affected. For the sick and elderly who succumbed after fifteen hours of being stuck in a school bus with no a/c in the midday Texas heat, there is no excuse. What is that saying “Primum non nocere”, “First, do no harm”?

Too many people feel that we cried wolf on this one. If the next one happens anywhere near recent memory, NOBODY is listening.

***Note to Houston mayor
Before you decide to mandatorily evacuate two million people that aren’t in a flood plain, give the people that actually are in the storm surge warning more than an hour to get out of your way.

Popularity: 50%

9/21/2005

Chown/Chmod Files By Reference

Working on shared server, you can easily create files under a user's account with root or admin privileges, leaving the user with no way to edit or delete the files. Drop the following alias' into your .bashrc so you can easily chown and chmod to the user's user, group and permissions by referencing a file.

alias rchown='chown --reference '
alias rchmod='chmod --reference '

To use:

rchown referencefile *
rchmod referencefile *

Or put it all together in a shell script refch.sh:

#!/bin/bash

if [ "$#" -lt 2 ]; then
echo "Usage: `basename $0` referencefile files [params]";
exit 1
fi

chown $3 --reference $1 $2
chmod $3 --reference $1 $2

if [[ "$3" = *R* ]]; then
chmod $3 +X $2
fi

exit 0

Download refch.sh

To use:

refch.sh referencefile adminfile
refch.sh referencefile . -R

The '-R' option means recursive, or act on every selected file in this directory and every subdirectory recursively.

Popularity: 14%

Next Page »


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

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

Close
E-mail It