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