Znalazłem cos takiego:
<?php
class CURL {
var $callback = false;
function setCallback($func_name) {
$this->callback = $func_name;
}
function doRequest($method, $url, $vars) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
$data = curl_exec($ch);
curl_close($ch);
if ($data) {
if ($this->callback)
{
$callback = $this->callback;
$this->callback = false;
return call_user_func($callback, $data);
} else {
return $data;
}
} else {
return curl_error($ch);
}
}
function get($url) {
return $this->doRequest('GET', $url, 'NULL');
}
function post($url, $vars) {
return $this->doRequest('POST', $url, $vars);
}
}
function aktualizacja_statusu($id, $status) {
// Aktualizacja/dodanie do bazy danych
$sql = "SELECT COUNT(*) as count FROM rs_links WHERE id=" . (int)$id;
if (!($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Błąd pobrania z rs_links", '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if ($row['count'] > 0) {
// Aktualizacja
$sql = "UPDATE rs_links SET last_checked = " . time() . ", status='" . $status . "' WHERE id=" . (int
)$id; if (!($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Błąd aktualizacji rs_links.", '', __LINE__, __FILE__, $sql);
}
} else {
// Dodanie
$sql = "INSERT INTO rs_links (id, last_checked, status) VALUES (" . (int
)$id . ", " . time() . ", '" . $status . "')"; if (!($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Błąd aktualizacji rs_links.", '', __LINE__, __FILE__, $sql);
}
}
// Usunięcie z rs_checker
$sql = "DELETE FROM rs_checker WHERE id=" . (int)$id;
if (!($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Błąd aktualizacji rs_checker.", '', __LINE__, __FILE__, $sql);
}
}
$curl = &new CURL();
// Aktualizacja wszystkich linków w rs_checker
$sql = "SELECT * FROM rs_checker";
if (!($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Błąd pobierania danych z rs_checker", '', __LINE__, __FILE__, $sql);
}
$linki_do_sprawdzenia = array();
$i = 0;
$subset = 0;
$linki_na_runde = 100;
while($row = $db->sql_fetchrow($result)) {
if ($i >= ($linki_na_runde - 1)) {
$subset++;
$i = 0;
}
$linki_do_sprawdzenia[$subset][$row['id']] = $row['link'];
$i++;
}
$db->sql_freeresult($result);
foreach($linki_do_sprawdzenia as $linki_do_sprawdzenia_teraz) {
$linki_do_sprawdzenia_teraz_ids = array();
foreach($linki_do_sprawdzenia_teraz as $id => $link) {
$linki_do_sprawdzenia_teraz_ids[] = $id;
}
$response = '';
$attempts = 0;
while (strlen($response) < 1) {
// Ilość powtórzeń przed zabiciem skryptu
if ($attempts >= 5) {
die('Wykonano 5 powtórzeń do Rapidshare, poddaje się...');
}
// Sprawdzanie linków przez system RS.com
$links = implode("\n", $linki_do_sprawdzenia_teraz); $response = $curl->post('http://rapidshare.com/cgi-bin/checkfiles.cgi', array('urls' => $links));
}
// Sprawdza które linki są poprawne
$pattern = '|File ([0-9]+) ([^)]+) found|i';
$poprawne_linki = array();
if (count($matches[1
]) > 0
) {
foreach ($matches[1] as $id) {
$poprawne_linki[] = $id;
aktualizacja_statusu($id, '1');
}
}
// Linki które nie zostały odnalezione a tym samym uznane za martwe
$martwe_linki = array_diff($linki_do_sprawdzenia_teraz_ids, $poprawne_linki);
if (count($martwe_linki) > 0
) {
foreach ($martwe_linki as $id) {
aktualizacja_statusu($id, '0');
}
}
}
?>
Źródło:
http://blog.brodowski.net.pl/2008/01/01/sp...-rapidsharecom/Czy ktoś ma pojęcie jak tego użyć?