function parseHeroBigIcon() { $result = mysql_query("SELECT id, slug FROM heroes"); $i = 0; while ($hero = mysql_fetch_array($result)) { $mas = explode("-", $hero['slug']); $hero_name = implode("_", $mas); $link = "/img/heroes/" . $hero_name . "/icon.jpg"; $path = "images/heroes_icons_big"; $filename = $hero_name . ".jpg"; $image_server_path = download_img($link, $filename, $path); if (!$image_server_path) { $log .= "Ошибка: " . $hero_name . "\r\n"; $names .= $hero_name; } else { $server_path = mysql_real_escape_string($image_server_path); $log .= "Успех: " . $hero_name . "\r\n"; $result2 = mysql_query("UPDATE heroes SET icon_big='{$server_path}' WHERE id='{$hero[id]}'"); if (!$result2) { $log .= "Ошибка загрузки в базу - " . $hero_name . "---" . mysql_error() . "\r\n"; } else { $log .= "Успех загрузки в базу - " . $hero_name . "\r\n\r\n"; } } sleep(30); } file_put_contents("log.txt", $log); file_put_contents("names-err.txt", $names); }
function part_set_image(&$picts_id, &$prod_id, $start_pos) { $start_time = time(); $total = get_option('merlion_total_images'); $items = get_option('merlion_download_images'); $cur_sec = get_option('merlion_current_second'); $request = get_option('merlion_count_request'); if (!is_array($request)) { $request = array(); } $count = 0; $begin = time(); for ($i = $start_pos; $i < count($items); $i++) { if (item_exists($items[$i]->No, $prod_id)) { if (!array_key_exists($items[$i]->No, $picts_id)) { if (get_post_meta($prod_id[$items[$i]->No], '_product_image_gallery', true)) { $picts_id[$items[$i]->No] = split(',', get_post_meta($prod_id[$items[$i]->No], '_product_image_gallery', true)); } else { $picts_id[$items[$i]->No] = array(); } } $pic_exists = picture_exists($items[$i]->FileName); if (!$pic_exists) { $total++; if ($total == 290) { return -1; } if (array_sum($request) + $count >= 119) { $request[$cur_sec] = $count; $cur_sec = $cur_sec == 9 ? 0 : $cur_sec + 1; $begin = time(); sleep(1); $count = 0; } $count++; error_log(current_time('mysql') . " Total {$total} \r\n", 3, "connect.log"); $res = download_img($items[$i]->FileName); if ($res) { error_log(current_time('mysql') . " Added image " . $i . ": " . $items[$i]->No . ": " . $items[$i]->FileName . " \r\n", 3, "connect.log"); $picts_id[$items[$i]->No][] = $res; } //else return 'error'; } else { if (!in_array($pic_exists, $picts_id[$items[$i]->No])) { $picts_id[$items[$i]->No][] = $pic_exists; } } } if (time() - $begin == 1) { $request[$cur_sec] = $count; $cur_sec = $cur_sec == 9 ? 0 : $cur_sec + 1; $begin = time(); } if (time() - $start_time > 20) { update_option('merlion_total_images', $total); update_option('merlion_current_second', $cur_sec); update_option('merlion_count_request', $request); $s = restart_set_image($picts_id, $prod_id, ++$i); return $s; } } update_option('merlion_current_second', $cur_sec); update_option('merlion_count_request', $request); }