示例#1
0
 /** Function launched daily to do some kind of cleanup...
  */
 function cronDaily()
 {
     global $db;
     $api = new Api();
     $api->log_caller = "cron-daily";
     // TODO: delete the old transcodes (kept for more than MAX_KEEP_TRANSCODE_DAYS days)
     // TODO: delete the old original videos (kept for more than MAX_KEEP_ORIGINAL_DAYS days) after having no job to do with them?
     // Announce the public transcoder to the discovery service :
     if (defined('PUBLIC_TRANSCODER') && PUBLIC_TRANSCODER && defined('TRANSCODER_NAME') && TRANSCODER_NAME != '' && defined('TRANSCODER_ADMIN_EMAIL') && TRANSCODER_ADMIN_EMAIL != '') {
         $f = @fopen("http://discovery.open-mediakit.org/?action=transcoder_is_available&name=" . urlencode(TRANSCODER_NAME) . "&email=" . urlencode(TRANSCODER_ADMIN_EMAIL) . "&url=" . urlencode(FULL_URL . "api") . "&version=" . OMKT_VERSION . "&application=OpenMediakitTranscoder", "rb");
         if ($f) {
             $js = "";
             while ($s = fgets($f, 1024)) {
                 $js .= $s;
             }
             fclose($f);
             $result = @json_decode($js);
             if (isset($result->code)) {
                 if ($result->code == 0) {
                     $api->log(LOG_INFO, "Successfully announced ourself as a Public Transcoder service at discovery.open-mediakit.org");
                 } else {
                     $api->log(LOG_INFO, "Something special happened when announcing ourself as a Public Transcoder service at discovery.open-mediakit.org. The message was : '" . $result->message . "'");
                 }
             } else {
                 $api->log(LOG_INFO, "An error was received when announcing ourself as a Public Transcoder service at discovery.open-mediakit.org. No error message reported");
             }
         }
     }
     // We disable (enabled=0) (and tell it by mail) daily, any user account whose last activity is more than 2 month ago AND last successfull cron is more than a month ago
     $disables = $db->qlist("SELECT * FROM users WHERE enabled=1 AND validated=1 AND lastactivity < DATE_SUB(NOW(), INTERVAL 62 DAY) AND lastcronsuccess < DATE_SUB(NOW(), INTERVAL 31 DAY);", NULL, PDO::FETCH_ASSOC);
     foreach ($disables as $disable) {
         $db->q("UPDATE users SET enabled=0 WHERE uid='" . $disable["uid"] . "';");
         $api->log(LOG_INFO, "disabled user " . $disable["uid"] . " (url was " . $disable["url"] . ") as being inactive and in error for too long.");
         $to = $disable["email"];
         $subject = _("Account disabled in the public OpenMediakit Transcoder");
         $message = sprintf(_("\nHi,\n\nDays ago, you subscribed to a public transcoder service.\n\nSince then, your account has not used our service for more than 2 months, and your website seems down since more than 1 month.\n\nAs a result, we just disabled your account for the application using our transcoding service.  \n\nFor your records, your website was located at %s.\n\nFeel free to resubscribe if you need to use this service later again,\n\n--\nRegards,\n\nThe OpenMediakit Transcoder public instance at\n%s\n"), $disable["url"], FULL_URL);
         $headers = 'From: ' . MAIL_FROMNAME . ' <' . MAIL_FROM . '>' . "\r\n" . 'Reply-To: ' . MAIL_FROM . "\r\n" . 'Content-type: text/plain; charset=utf-8' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
         mail($to, $subject, $message, $headers);
     }
     // for each disabled account
 }
示例#2
0
            break;
    }
}
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGQUIT, "sig_handler");
while (true) {
    // Cleanup daemons from this host
    $api->cleanupQueueLocks();
    // Search for a task
    $task = $api->getQueuedTaskLock(array(TASK_SEND_METADATA, TASK_SEND_TRANSCODE, TASK_SEND_METADATAERROR));
    if (!$task) {
        // we sleep for a little while, thanks to that, we can launch that process as soon as we want:
        // it will still do *nothing* for a little while when there is nothing to do ;)
        $api->log(LOG_DEBUG, "Nothing to do, sleeping...");
        sleep(60);
        continue;
    }
    $media = $api->mediaSearch(array("id" => $task["mediaid"]));
    if (!$media) {
        $api->log(LOG_CRIT, "Got task '" . $task["id"] . "' but media '" . $task["mediaid"] . "' not found!!");
        $api->setTaskFailedUnlock($task["id"]);
        continue;
    }
    $media = $media[0];
    $api->me = Users::get($task["user"]);
    $url = $api->me["url"];
    if (strpos($url, "?") !== false) {
        $url .= "&";
    } else {
示例#3
0
            break;
    }
}
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGQUIT, "sig_handler");
while (true) {
    // Cleanup daemons from this host
    $api->cleanupQueueLocks();
    // Search for a task
    $task = $api->getQueuedTaskLock(TASK_DOWNLOAD, "http");
    if (!$task) {
        // we sleep for a little while, thanks to that, we can launch that process as soon as we want:
        // it will still do *nothing* for a little while when there is nothing to do ;)
        $api->log(LOG_DEBUG, "Nothing to do, sleeping...");
        sleep(60);
        continue;
    }
    $media = $api->mediaSearch(array("id" => $task["mediaid"]));
    if (!$media) {
        $api->log(LOG_CRIT, "got task '" . $task["id"] . "' but media '" . $task["mediaid"] . "' not found");
        $api->setTaskFailedUnlock($task["id"]);
        continue;
    }
    $media = $media[0];
    $api->me = Users::get($task["user"]);
    // ok, we try to download the file, with curl, with timeout and range management
    $curl = curl_init();
    $options = array(CURLOPT_USERAGENT => $useragent, CURLOPT_HEADER => false, CURLOPT_FAILONERROR => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 600);
    curl_setopt_array($curl, $options);
示例#4
0
        if (substr($onecron["url"], 0, 7) == "http://" || substr($onecron["url"], 0, 8) == "https://") {
            if (strpos($onecron["url"], "?") !== false) {
                $onecron["url"] .= "&action=transcoder_cron&app_key=" . $onecron['clientkey'];
            } else {
                $onecron["url"] .= "?action=transcoder_cron&app_key=" . $onecron['clientkey'];
            }
            $urllist[] = array("url" => $onecron["url"], "uid" => $onecron["uid"]);
        }
    }
    if (empty($urllist)) {
        // nothing to do :
        sleep(60);
        // Let's try again in a minute
        continue;
    }
    $api->log(LOG_INFO, "Launching " . count($urllist) . " cron calls");
    // cron_callback($url, $content, $curlobj) will be called at the end of each http call.
    $cron->rolling_curl($urllist, "cron_callback");
}
// while true
function cron_callback($url, $content, $curl)
{
    global $cron, $api;
    $api->log(LOG_DEBUG, "return from cron call for url " . implode(":", $url) . " has http_code " . $curl["http_code"]);
    if (empty($url["uid"])) {
        return;
    }
    // not normal...
    if ($curl["http_code"] == 200) {
        $cron->cronCallOk($url["uid"]);
    } else {
示例#5
0
    }
    echo "oups";
}
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGQUIT, "sig_handler");
while (true) {
    // Cleanup daemons from this host
    $api->cleanupQueueLocks();
    // Search for a task
    $task = $api->getQueuedTaskLock(TASK_DO_METADATA);
    if (!$task) {
        // we sleep for a little while, thanks to that, we can launch that process as soon as we want:
        // it will still do *nothing* for a little while when there is nothing to do ;)
        $api->log(LOG_DEBUG, "Nothing to do, sleeping...");
        sleep(60);
        continue;
    }
    // Get the task's parameters */
    $params = unserialize($task["params"]);
    $media = $api->mediaSearch(array("id" => $task["mediaid"]));
    if (!$media) {
        $api->log(LOG_CRIT, "Got task '" . $task["id"] . "' but media '" . $task["mediaid"] . "' not found!!");
        $api->setTaskFailedUnlock($task["id"]);
        continue;
    }
    $media = $media[0];
    $api->me = Users::get($task["user"]);
    $adapterObject = $api->getAdapter($media["adapter"]);
    if (!$adapterObject) {
示例#6
0
    echo "oups";
}
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGQUIT, "sig_handler");
$all_settings = $api->getAllSettings();
while (true) {
    // Cleanup daemons from this host
    $api->cleanupQueueLocks();
    // Search for a task
    $task = $api->getQueuedTaskLock(TASK_DO_TRANSCODE);
    if (!$task) {
        // we sleep for a little while, thanks to that, we can launch that process as soon as we want:
        // it will still do *nothing* for a little while when there is nothing to do ;)
        $api->log(LOG_DEBUG, "Nothing to do, sleeping...");
        sleep(60);
        continue;
    }
    // Get the task's parameters */
    $params = $task["params"];
    $media = $api->mediaSearch(array("id" => $task["mediaid"]));
    if (!$media) {
        $api->log(LOG_CRIT, "Got task '" . $task["id"] . "' but media '" . $task["mediaid"] . "' not found!!");
        $api->setTaskFailedUnlock($task["id"]);
        continue;
    }
    $media = $media[0];
    $transcode = $api->transcodeSearch(array("id" => $params["transcode"]));
    $api->log(LOG_DEBUG, "Transcode search '" . $params["transcode"] . "' returns '" . print_r($transcode, 1) . "'");
    if (!$transcode) {
示例#7
0
    exit(1);
}
require_once __DIR__ . '/../../common.php';
require_once MODULES . '/api/libs/api.php';
$useragent = "OpenMediaKit-Transcoder/" . OMKT_VERSION . " (Download Daemon)";
$api = new Api();
$api->log_caller = "dummy-download-daemon";
while (true) {
    // Cleanup daemons from this host
    $api->cleanupQueueLocks();
    // Search for a task
    $task = $api->getQueuedTaskLock(TASK_DOWNLOAD, "dummy");
    if (!$task) {
        // we sleep for a little while, thanks to that, we can launch that process as soon as we want:
        // it will still do *nothing* for a little while when there is nothing to do ;)
        $api->log(LOG_DEBUG, "Nothing to do, sleeping...");
        sleep(60);
        continue;
    }
    $media = $api->mediaSearch(array("id" => $task["mediaid"]));
    if (!$media) {
        $api->log(LOG_CRIT, "got task '" . $task["id"] . "' but media '" . $task["mediaid"] . "' not found");
        $api->setTaskFailedUnlock($task["id"]);
        continue;
    }
    $media = $media[0];
    // ok, we try to download the file, with curl, with timeout and range management
    $curl = curl_init();
    $options = array(CURLOPT_USERAGENT => $useragent, CURLOPT_HEADER => false, CURLOPT_FAILONERROR => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 600);
    curl_setopt_array($curl, $options);
    curl_setopt($curl, CURLOPT_URL, $task["params"]["url"]);