To tak przemyślałem temat...
Tworzysz sobie bazę danych w moim przypadku o nazwie: wrzuta
A w niej tabelę: users
CREATE TABLE `users` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`status` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=1 ;
Plik php wygląda tak:
<?php
function save($array) {
foreach ($array as $row) {
mysql_query('INSERT INTO `users` VALUES(null, "'.$row.'", 0)'); }
return true;
}
function getUsers($url) {
$site = str_replace('http://www.wrzuta.pl/', '#', $site); $site = str_replace('http://c.wrzuta.pl/', '#', $site); $site = preg_replace('#http://c[0-9]+\.wrzuta\.pl/#', '#', $site);
return $users;
}
$select = mysql_query('SELECT `id`, `name` FROM `users` WHERE `status` = 0 LIMIT 20');
if (!save(getUsers($data['name']))) {
break;
}else{
mysql_query('UPDATE `users` SET `status` = 1 WHERE `id` = '.$data['id']); }
}
}else{
save(getUsers('http://www.wrzuta.pl/'));
}
?>
Obok pliku php tworzysz sobie plik bat (zakładam że jesteś na windowsie)
W moim przypadku wygląda on tak:
Kod
@ECHO OFF
:start
php wrzuta.php
goto start
Może się zmienić ścieżka do php (możesz nie mieć dodanego w zmiennych środowiskowych) i nazwa pliku.
Teraz idąc dalej stworzyłem kod, który wykonuje to zadanie troszkę szybciej
<?php
function save($array) {
foreach ($array as $row) {
mysql_query('INSERT INTO `testy` VALUES(null, "'.$row.'", 0)'); }
return true;
}
function getUsers($arr) {
$m_h = curl_multi_init();
foreach ($arr as $key => $val) {
$ch[$key] = curl_init($val);
curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($m_h, $ch[$key]);
}
$running=null;
do{
curl_multi_exec($m_h,$running);
}while($running > 0);
foreach ($ch as $key => $val) {
$sites[$key] = curl_multi_getcontent($val);
curl_multi_remove_handle($m_h, $val);
}
curl_multi_close($m_h);
foreach ($sites as $key => $val) {
mysql_query('UPDATE `testy` SET `status` = 1 WHERE `id` = '.$key); $val = str_replace('http://www.wrzuta.pl/', '#', $val); $val = preg_replace('#http://c[0-9]+\.wrzuta\.pl/#', '#', $val); }
save($users);
}
$select = mysql_query('SELECT `id`, `name` FROM `testy` WHERE `status` = 0 LIMIT 80');
$users[$data['id']] = $data['name'];
}
getUsers($users);
}else{
getUsers
(array('http://www.wrzuta.pl/')); }
?>