Example #1
0
 protected function test_links($links)
 {
     $this->worker->enable_limit(self::MAX_DOWNLOAD_SIZE)->add($links)->exec();
     foreach ($links as $id => $link) {
         $status = $this->test_result($link);
         if ($status === false) {
             continue;
         }
         Database::update('post_url', array('status' => $status, 'lastcheck' => Database::unix_to_date()), $id);
         if ($status == self::STATUS_UNKNOWN) {
             $this->create_unknown_file($link);
         }
     }
     $this->worker->flush();
     $keys = array_keys($links);
     $post_ids = Database::join('post_link_url', 'plu.link_id = pl.id')->join('post_url', 'plu.url_id = pu.id')->get_vector('post_link', 'post_id', Database::array_in('pu.id', $keys), $keys);
     $post_ids = array_unique($post_ids);
     foreach ($post_ids as $post_id) {
         $status = new Model_Post_Status($post_id);
         $status->load()->calculate()->commit();
     }
     $update_ids = Database::join('post_update_link_url', 'pulu.link_id = pul.id')->join('post_url', 'pulu.url_id = pu.id')->get_vector('post_update_link', 'update_id', Database::array_in('pu.id', $keys), $keys);
     $update_ids = array_unique($update_ids);
     foreach ($update_ids as $update_id) {
         $status = new Model_Post_Update_Status($update_id);
         $status->load()->calculate()->commit();
     }
 }
Example #2
0
 public function set($key, $value, $expire = null)
 {
     if (is_array($value) || is_object($value)) {
         $value = Database::pack($value);
     }
     if (empty($expire)) {
         $expire = DAY;
     }
     $expire = Database::unix_to_date(time() + $expire);
     $insert = array("key" => $key, "value" => $value, "expires" => $expire);
     Database::replace("cache", $insert, "key");
 }
Example #3
0
	public static function save ($filename, $username, $resized, $user_id = 0, $timer = false) {
		
		$sizes = getimagesize($filename);
		
		$insert = array(
			'name' => pathinfo($filename, PATHINFO_FILENAME),
			'resized' => $resized,
			'width' => $sizes[0],
			'height' => $sizes[1],
			'weight' => filesize($filename),
			'extension' => pathinfo($filename, PATHINFO_EXTENSION),
			'timer' => (int) $timer,
			'meta' => self::get_base_meta($username),
			'area' => 'main',
			'user_id' => $user_id
		);
		
		Database::insert('art', $insert);
		
		$update = array('last_draw' => Database::unix_to_date());
		
		Database::update('user', 'id = ?', $update, $user_id);
	}
Example #4
0
#!/usr/bin/php
<?php 
include_once 'inc.common.php';
define('LOCK_FILE', '/tmp/cron_lock');
$cron = new Cron();
ini_set('memory_limit', '1024M');
ini_set('time_limit', '1800');
if ($key = key($_GET)) {
    $cron->process($key);
    var_dump(memory_get_peak_usage(true));
    exit;
}
if (file_exists(LOCK_FILE) && filemtime(LOCK_FILE) > time() - 3600) {
    exit;
}
$time = Database::unix_to_date();
$tasks = Database::order('id', 'asc')->get_vector('cron', array('function', 'period'), 'last_time < ?', $time);
if (empty($tasks)) {
    exit;
}
touch(LOCK_FILE);
foreach ($tasks as $task => $period) {
    $cron->process($task);
    $nexttime = Database::unix_to_date(Transform_Time::parse($period) - 15);
    Database::update('cron', array('last_time' => $nexttime), 'function = ?', $task);
}
unlink(LOCK_FILE);