Depends on what OS and FTP server you are using...if I wanted to do this on my system (freeBSD and ProFTPd) I would run a ps command through PHP:
ps -U ftp
ftp is the user account that all anonymous connections are aliases to. So, this ps command would show me the number of active anonymous connections. I would then parse that info with PHP and just count up the entries....