Post Calendar
July 2010 M T W T F S S « Jan 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
PHP and set_locale on Debian
I like to use set_locale and money_format in my applications for flexibility. You never know when you’re going to go global!
I had been using RedHat for a long time, and switched to Debian as I like the distro a lot better. I couldn’t get set_locale to work. Here’s what I was trying, which is almost straight out of the PHP online manual:
<?php
setlocale(LC_MONETARY, 'en_US');
echo money_format('%.2n', $amount);
?>
But no joy. I finally figured out that the locales are a bit different in Debian. You can use the ‘locale’ command to show what locales are actually installed on your server:
silver:~# locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= silver:~# locale -a C en_US.utf8 POSIX silver:~#
You can see that the locale on Debian is actually ‘en_US.utf8′. A quick change and my money formatting code was back to it’s old self.
<?php
setlocale(LC_MONETARY, 'en_US.utf8');
echo money_format('%.2n', $amount);
?>
Posted in Uncategorized
Leave a comment
Preventing Daily mail.log rotation on Debian
My preference for server side Linux is Debian 4. As with most distributions, most of the system files are rotated on a daily, weekly, and monthly basis by logrotate. For example, in Debian the log files for apache2, aptitude, and clamav are all handled by logrotate, and the configuration files are located in /etc/logrotate.d/
/var/log/apache2/*.log {
monthly
missingok
rotate 24
compress
delaycompress
notifempty
create 640 root www-data
sharedscripts
postrotate
if [ -f /var/run/apache2.pid ]; then
/etc/init.d/apache2 restart > /dev/null
fi
endscript
}
I was finding that my postfix log, mail.log, was getting rotated more often, even though it was really not very large. Sometimes it would rotat every day, sometimes every two days. But I couldn’t find any logrotate config files for the postfix logs. After a bit of searching I discovered that the mail facilities are handled by savelog, which operates in sysklogd. sysklogd is a script that runs in the daily cron at /etc/cron.daily/sysklogd.
A bit of the script is here, and you can see the savelog command:
cd /var/log
for LOG in `syslogd-listfiles`
do
if [ -s $LOG ]; then
savelog -g adm -m 640 -u root -c 7 $LOG >/dev/null
fi
done
So what is syslogd-listfiles? It will show you all files that are to be logged with syslogd.
silver:/etc/cron.daily# syslogd-listfiles --all
/var/log/mail.warn
/var/log/uucp.log
/var/log/user.log
/var/log/daemon.log
/var/log/messages
/var/log/debug
/var/log/auth.log
/var/log/mail.err
/var/log/syslog
/var/log/mail.log
/var/log/mail.info
/var/log/kern.log
/var/log/lpr.log
Posted in Uncategorized
Leave a comment