September 2005

Lighttpd Startup Script

by damonp on September 30, 2005

in SysAdmin

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: 4%

{ 0 comments }

Download a Remote File Using PHP

by damonp on September 29, 2005

in PHP,Snippets

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

Update: 3-Feb-11
Updated function to download a remote file with PHP and cURL.

Popularity: 48%

{ 9 comments }

Delete Files Newer Than

29 September 2005

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

Read the full article →

Lighttpd Update

27 September 2005

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 [...]

Read the full article →

The Other Costs of Hurricane Rita

27 September 2005

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 [...]

Read the full article →

Chown/Chmod Files By Reference

21 September 2005

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. [...]

Read the full article →

DLoads Pepper Released

20 September 2005

Mint is a live stats package from Shaun Inman. Pepper is an API for adding modules to the core Mint application. This is the initial release of DLoads which tracks files downloaded and provides live stats through the Mint interface. Full information at Pepper DLoads.

Read the full article →

iTerm Here Applescript Update

20 September 2005

Last week I posted a combination shell script, Applescript to open a new iTerm session in the local directory or a specified directory. Version 1.2 is available for download now. The Applescript was fixed so the new session always opens in the current window.

Read the full article →

Shortstat Hack To Remove Local Views

20 September 2005

Prevent your own pageviews from appearing in Shortstat stats Create a file called _getmyip.php in your Shortstat directory with the following code: <?php     $thisip = $_SERVER[’REMOTE_ADDR’];      $fp = fopen(’_myip.php’, ‘w’);     $buffer = ‘<’.'? $_myip = "’.$thisip.’"; ?’.'>’;     fwrite($fp, $buffer, strlen($buffer));             if(fclose($fp)) [...]

Read the full article →

Find Large Files Wasting Disk Space

19 September 2005

Find files over 8000k on all mounted drives and print the filesize and path: find /$1 -mount -size +8000k -exec ls -sh {} \; This one is suitable for a cron job. It does the same, sorts by filesize and mails the result to the supplied email address. find /$1 -mount -size +8000k -exec ls [...]

Read the full article →