Beispiel #1
0
function main()
{
    global $CONFIG, $SCHEDULER_LAST;
    print "\n";
    printd("start\n");
    printd("cwd: " . getcwd() . "\n");
    $date = date('Ymd');
    fileWrite($CONFIG['PHPDL_STACK_PIDFILE'], posix_getpid());
    $n = 0;
    while (!$SHUTDOWN) {
        $n++;
        $dbh = dbConnect();
        $scheduler = scheduler($dbh);
        $filesDownloading = filesDownloading($dbh);
        if ($SCHEDULER_LAST != $scheduler) {
            plog("scheduler '{$scheduler}' matched\n");
            $SCHEDULER_LAST = $scheduler;
        }
        $res = mysql_query("select id from packets where archive = '0' and active = '1' and ftime = '0' order by sortnr, id;", $dbh);
        if (mysql_num_rows($res)) {
            while ($row = mysql_fetch_assoc($res)) {
                $packet = new dlpacket($CONFIG['DB_HOST'], $CONFIG['DB_NAME'], $CONFIG['DB_USER'], $CONFIG['DB_PASS']);
                if ($packet->loadById($row['id'])) {
                    $packetDirBn = getPacketFilename($packet->get('id'), $packet->get('name'));
                    $packetDownloadDir = 'downloads/loading/' . $packetDirBn;
                    $packetFinishedDir = 'downloads/finished/' . $packetDirBn;
                    if ($packet->loadFiles()) {
                        if ($packet->filesUnfinished()) {
                            if ($scheduler > 0) {
                                if ($filesDownloading < $CONFIG['DL_SLOTS']) {
                                    if (!$packet->get('stime')) {
                                        $packet->save('stime', mktime());
                                    }
                                    if ($nextfile = $packet->getFileNextUnfinished()) {
                                        while ($nextfile->get('error')) {
                                            printd("nextfile " . $nextfile->get('id') . "\n");
                                            $nextfile = $packet->getFileNextUnfinished();
                                            if (!$nextfile) {
                                                break;
                                            }
                                            sleep(1);
                                        }
                                        if ($nextfile) {
                                            printd("packet " . $packet->get('id') . ": download " . $nextfile->get('id') . "\n");
                                            $sh = 'php wget.php ' . $nextfile->get('id') . ' 1>> log/wget.' . $date . '.log 2>> log/wget.' . $date . '.log &';
                                            printd("exec '{$sh}'\n");
                                            system($sh);
                                            sleep(1);
                                            break;
                                        }
                                    }
                                } else {
                                    plog("no free download slots (" . $CONFIG['DL_SLOTS'] . ")\n");
                                }
                            }
                        } else {
                            printd("packet " . $packet->get('id') . ": all files finished\n");
                            if (!$packet->get('stime')) {
                                $packet->set('stime', mktime());
                            }
                            $packet->save('ftime', mktime());
                            $packet->md5Verify();
                            $packet->sizeVerify();
                            if (!$packet->fileErrors()) {
                                if (file_exists($packetFinishedDir)) {
                                    $files = scandir($packetDownloadDir);
                                    foreach ($files as $file) {
                                        if ($file != '.' && $file != '..' && file_exists($packetDownloadDir . '/' . $file)) {
                                            rename($packetDownloadDir . '/' . $file, $packetFinishedDir . '/' . $file);
                                        }
                                    }
                                    reset($files);
                                    rmdir($packetDownloadDir);
                                } else {
                                    rename($packetDownloadDir, $packetFinishedDir);
                                }
                            }
                        }
                    }
                }
                unset($packet);
            }
        } else {
            plog("no active download\n");
        }
        dbClose($dbh);
        $SHUTDOWN = shutdownCheck();
        sleep(5);
    }
    shutdown();
}
Beispiel #2
0
							</form>
							<tr><td colspan="2">&nbsp;</td></tr>
						' : '');
                    }
                }
            }
            $smarty->display($tpl, $cacheId);
            break;
        case 'scheduler':
            $tpl = $a . '.tpl';
            $cacheId = $a;
            if (!$smarty->isCached($tpl, $cacheId)) {
                smartyAssignStd($smarty);
                smartyAssignMenu($smarty, $user);
                $dbh = dbConnect();
                $schedulerActive = abs(scheduler($dbh));
                $schedulerOut = '';
                $res = mysql_query("select * from scheduler order by sortnr;", $dbh);
                $schedulerNum = mysql_num_rows($res);
                $schedulerC = 0;
                while ($sched = mysql_fetch_assoc($res)) {
                    $schedulerC++;
                    $move = '';
                    if ($schedulerNum > 1) {
                        if ($schedulerC == 1) {
                            $move = '<a href="?a=schedulerMoveExec&amp;id=' . $sched['id'] . '&amp;sortnr=' . $sched['sortnr'] . '&amp;dir=d"><img src="img/button_down.gif" border="0" /></a>';
                        } elseif ($schedulerC <= $schedulerNum - 1) {
                            $move = '<a href="?a=schedulerMoveExec&amp;id=' . $sched['id'] . '&amp;sortnr=' . $sched['sortnr'] . '&amp;dir=d"><img src="img/button_down.gif" border="0" /></a> <a href="?a=schedulerMoveExec&amp;id=' . $sched['id'] . '&amp;sortnr=' . $sched['sortnr'] . '&amp;dir=u"><img src="img/button_up.gif" border="0" /></a>';
                        } else {
                            $move = '<a href="?a=schedulerMoveExec&amp;id=' . $sched['id'] . '&amp;sortnr=' . $sched['sortnr'] . '&amp;dir=u"><img src="img/button_up.gif" border="0" /></a>';
                        }