can this php function be written to perform better?
Yeah, you can optimize your query,

 $res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND userid = $userid");


As this query will first check for seeder which has 'yes' and then for userid. So you can first check for userid, then for seeder. This will improve performance

$res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE userid = $userid" AND seeder = 'yes' );