johannes85 / PHP-Torrent-Scraper

Scrape torrents stats with PHP using HTTP or UDP
http://blog.johnimedia.de/
66 stars 22 forks source link

little optimization #1

Open bkfox opened 12 years ago

bkfox commented 12 years ago

In the udp scapper, you should invert

foreach($infohash as $hash){
if(!preg_match('#^[a-f0-9]{40}$#i',$hash)){ throw new ScraperException('Invalid infohash: ' . $hash . '.'); }
}
if(count($infohash) > 74){ throw new ScraperException('Too many infohashes provided.'); }

by:

if(count($infohash) > 74){ throw new ScraperException('Too many infohashes provided.'); }
foreach($infohash as $hash){
if(!preg_match('#^[a-f0-9]{40}$#i',$hash)){ throw new ScraperException('Invalid infohash: ' . $hash . '.'); }
}

it should be better for perfs

johannes85 commented 12 years ago

It would be nice if you can send me this change as pull request