Created
September 1, 2010 10:24
-
-
Save ivanscm/560510 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function StartDownload() { | |
| include($_SERVER['DOCUMENT_ROOT']."/engine/functions/db.php"); | |
| include($_SERVER['DOCUMENT_ROOT']."/engine/functions/grabe_download.php"); | |
| ignore_user_abort(1); | |
| set_time_limit (0); | |
| $get_action = 'SELECT status, id, type, url, url2, name, file_name FROM `files` WHERE `status`=\'forward\' LIMIT 1'; | |
| $is_action = 'SELECT status, id FROM `files` WHERE `status`=\'runload\' LIMIT 1'; | |
| if (file_exists($_SERVER['DOCUMENT_ROOT']."/work_status/stop_downloads.sys")){ | |
| die ('forb'); | |
| } | |
| $result = mysql_query($is_action); | |
| if (mysql_num_rows($result) == 1) | |
| { | |
| echo 'runload'; | |
| } else { | |
| $result = mysql_query($get_action); | |
| if (mysql_num_rows($result) == 1) | |
| { | |
| echo 'ok'; | |
| $row = mysql_fetch_array($result); | |
| // узнать размер и обновить и поставить метку что качается | |
| $size = GetUrlSize($row['url']); | |
| $file_traffic = fopen($_SERVER['DOCUMENT_ROOT']."/work_status/incoming_traffic.sys", "r+"); | |
| flock($file_traffic, LOCK_EX); | |
| $traffic = doubleval(fgets($file_traffic)); | |
| $traffic += $size; | |
| ftruncate($file_traffic, 0); | |
| fseek($file_traffic, 0, SEEK_SET); | |
| fwrite($file_traffic, $traffic); | |
| fflush($file_traffic); | |
| flock($file_traffic, LOCK_UN); | |
| fclose($file_traffic); | |
| mysql_query("UPDATE `files` SET `size`= '{$size}', `status`= 'runload' WHERE `id` = '{$row['id']}'"); | |
| // качаем | |
| $temp_name = md5($row['url']); | |
| $ch = curl_init($row['url']); | |
| $fp = fopen("../files/".$temp_name, "w"); | |
| curl_setopt($ch, CURLOPT_FILE, $fp); | |
| curl_setopt($ch, CURLOPT_HEADER, 0); | |
| curl_exec($ch); | |
| curl_close($ch); | |
| fclose($fp); | |
| // поставить метку что скачан | |
| mysql_query("UPDATE `files` SET `status`= 'done' WHERE `id` = '{$row['id']}'"); | |
| // запуститься опять | |
| $http = fsockopen($_SERVER['SERVER_NAME'] ,80); | |
| fputs($http, "GET http://".$_SERVER['SERVER_NAME']."/engine/graber_procces.php?action=start HTTP/1.0\r\n"); | |
| fputs($http, "Host: ".$_SERVER['SERVER_NAME']."\r\n"); | |
| fputs($http, "\r\n"); | |
| fclose($http); | |
| } else { | |
| echo 'allok'; | |
| } | |
| } | |
| } | |
| function StartForceDownload(){ | |
| unlink($_SERVER['DOCUMENT_ROOT']."/work_status/stop_downloads.sys"); | |
| StartDownload(); | |
| } | |
| function StopDownload(){ | |
| $f = fopen($_SERVER['DOCUMENT_ROOT']."/work_status/stop_downloads.sys", "w"); | |
| fwrite($f, "стой сука :)"); | |
| fclose($f); | |
| echo 'ok'; | |
| } | |
| if (isset($_GET['action'])) { | |
| switch ($_GET['action']) { | |
| case "start": | |
| StartDownload(); | |
| break; | |
| case "stop": | |
| StopDownload(); | |
| break; | |
| case "force": | |
| StartForceDownload(); | |
| break; | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment