If you are using Windows, there is a nice DOS exe program which will print out info on a midi file.
Goto: http://www.gnmidi.com
Scroll down to the Free Files section and download mididir.zip
To use the command:
$info = system("mididir.exe -l filename.mid");
For example, I invoked this command on a file called: glaubean.mid and the program returned this output:
C:\Documents and Settings\hehe\My Documents\glaubean.mid: Wir glauben as Christkind (Günter Nagler, 14.11.1998) (83 kb, format 1, 14 tracks, 4:11)
As you can guess, the last part of the string (4:11) is the length. Now, just use some kind of regular expression (or explode into array using the space character) and access the time.
The mididir program is very fast and you can enter multiple filenames (i think). So it should take a long time to get time values.
hope this comes to use if you (or anyone) is using windows!
-sridhar