ChambeRFienD Posted August 17, 2006 Share Posted August 17, 2006 Well, I'm writing a script to check a list of domains in a CSV file to see if they are being parked at GoDaddy or not. The script works, it just takes FOREVER to check just 2 domain names...[code]<h1>CSV Domain Check</h1><?php$row = 1;$handle = fopen("file.csv", "r");while (($data = fgetcsv($handle, 500, ",")) !== FALSE) {$num = count($data);for ($c=0; $c < $num; $c++) { fopen($data[$c], "r"); $handle2 = fopen($data[$c], "r"); $contents = stream_get_contents($handle2, 1024); $matchPattern = '.*Coming Soon!.*'; if (ereg($matchPattern, $contents, $result)) { echo $data[$c] . "<br />\n"; } else { } }}fclose($handle);?> [/code]Anyone have any idea on how to make this go faster? Link to comment https://forums.phpfreaks.com/topic/17875-script-taking-way-too-long/ Share on other sites More sharing options...
448191 Posted August 19, 2006 Share Posted August 19, 2006 I'ts probably because your using ereg() on HUGE strings (especially the sites that actually have content).Use strpos('Coming Soon!'). Link to comment https://forums.phpfreaks.com/topic/17875-script-taking-way-too-long/#findComment-77198 Share on other sites More sharing options...
Barand Posted August 19, 2006 Share Posted August 19, 2006 Why do you open everything twice?[code] fopen($data[$c], "r"); $handle2 = fopen($data[$c], "r");[/code]Also you never close $handle2 Link to comment https://forums.phpfreaks.com/topic/17875-script-taking-way-too-long/#findComment-77227 Share on other sites More sharing options...
Daniel0 Posted August 19, 2006 Share Posted August 19, 2006 [code]<h1>CSV Domain Check</h1><?php$row = 1;$handle = fopen("file.csv", "r");while (($data = fgetcsv($handle, 500, ",")) !== FALSE) {$num = count($data);for ($c=0; $c < $num; $c++) { $handle2 = fopen($data[$c], "r"); $contents = stream_get_contents($handle2, 1024); if (preg_match('/.*Coming Soon!.*/', $contents, $result)) { echo $data[$c] . "<br />\n"; } else { } } fclose($handle2);}fclose($handle);?>[/code]Try that. Link to comment https://forums.phpfreaks.com/topic/17875-script-taking-way-too-long/#findComment-77232 Share on other sites More sharing options...
448191 Posted August 19, 2006 Share Posted August 19, 2006 Simpler and faster:- file_get_contents() is faster than using fopen() and stream_get_contents().- strpos() is A LOT faster than ereg() or preg_match() (Don't use those unless nessecary).[code]<?php$row = 1;$fp = fopen("file.csv", "r");while (($data = fgetcsv($fp, 500, ",")) !== false) { $num = count($data); for ($c=0; $c < $num; $c++) { $contents = file_get_contents($data[$c]); if (strpos($contents,'Coming Soon!') !== false) { echo $data[$c] . "<br />\n"; } }}fclose($fp);?>[/code] Link to comment https://forums.phpfreaks.com/topic/17875-script-taking-way-too-long/#findComment-77250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.