function thread_shutdown() { $isError = false; if ($error = error_get_last()) { switch ($error['type']) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: $isError = true; break; } } if ($isError) { date_default_timezone_set('Europe/Ljubljana'); if (defined("THREAD") && defined("THREAD_TYPE")) { print date("d.m.Y H:i:s") . " :: " . THREAD_TYPE . " Thread :: " . str_pad(THREAD, 3, "0", STR_PAD_LEFT) . " :: Script execution halted ({$error['message']})\n"; } else { print date("d.m.Y H:i:s") . " :: Script execution halted ({$error['message']})\n"; } if (defined("THREAD") && defined("THREAD_TYPE")) { require_once dirname(__FILE__) . '/../common/lib/Net/Gearman/Client.php'; print date("d.m.Y H:i:s") . " :: " . THREAD_TYPE . " Thread :: " . str_pad(THREAD, 3, "0", STR_PAD_LEFT) . " :: Starting workers restart...\n"; $set = new Net_Gearman_Set(); $task = new Net_Gearman_Task("Worker_Restarter", 1); $task->type = Net_Gearman_Task::JOB_BACKGROUND; $set->addTask($task); $client = new Net_Gearman_Client(array('127.0.0.1:4730')); $client->runSet($set); } } }
/** * shutdown handler * @return void * */ public function onShutdownHandler() { if ($e = error_get_last()) { if (defined("THREAD") && defined("THREAD_TYPE")) { require_once dirname(__FILE__) . '/../../../common/lib/Net/Gearman/Client.php'; print date("d.m.Y H:i:s") . " :: " . THREAD_TYPE . " Thread :: " . str_pad(THREAD, 3, "0", STR_PAD_LEFT) . " :: Starting workers restart...\n"; $set = new Net_Gearman_Set(); $task = new Net_Gearman_Task("Worker_Restarter", 1); $task->type = Net_Gearman_Task::JOB_BACKGROUND; $set->addTask($task); $client = new Net_Gearman_Client(array('127.0.0.1:4730')); $client->runSet($set); } $this->raiseEvent('onEndRequest', new CEvent($this)); } }
function __construct() { $post_id = $_REQUEST['id']; $this->db = $db = get_db_connectiuon(); list($sessionkey, $cookies) = get_login_cookie($db); $this->sessionkey = $sessionkey; $this->page = $page = getPage(); $pid = getmypid(); $this->postid = $postid = (int) $_REQUEST['postid']; if (preg_match('%^http://([a-z\\-_.]+\\.)+\\w{2,4}(/mobile)?/post/\\d+$%i', $link = (string) $_REQUEST['permalink'])) { $this->permalink = $link; } else { $link = ''; } $uniqkey = "{$pid}-{$postid}-{$sessionkey}"; $set = new Net_Gearman_Set(); $task = new Net_Gearman_Task('reblog', array(cookies => $cookies, postid => $postid, sessionkey => $sessionkey, permalink => $this->permalink, token => $_REQUEST['token'], uniqkey => $uniqkey), $uniqkey, Net_Gearman_Task::JOB_BACKGROUND); // $task->attachCallback('result'); $set->addTask($task); $client = new Net_Gearman_Client(array('localhost:37003')); $client->runSet($set); }
/** * publish a message * * @param string $msg * @return boolean */ public function _publish($msg) { $gearman = $this->getPublisher(); // publish the message... $task = new Net_Gearman_Task($this->getField('bind_name'), $msg, $this->getUid(), Net_Gearman_Task::JOB_BACKGROUND); $set = new Net_Gearman_Set(); $set->addTask($task); // turn off strict errors since Net Gearman throws a lot of strict errors, this is // a terrible way to do it, but I don't want to edit the original code... $current_error_level = error_reporting(); $change_error_level = (bool) ($current_error_level & E_STRICT); if ($change_error_level) { error_reporting($current_error_level ^ E_STRICT); } //if $gearman->runSet($set); if ($change_error_level) { error_reporting($current_error_level); } //if $job_handle = $task->handle; return !empty($job_handle); }
<?php require_once 'Net/Gearman/Client.php'; $email = $_REQUEST['email']; $password = $_REQUEST['password']; $postid = $_REQUEST['postid']; if ($email == '' or $password == '' or $postid == '') { print 0; exit; } $pid = getmypid(); $set = new Net_Gearman_Set(); $task = new Net_Gearman_Task('reblog', array('email' => $email, 'password' => $password, 'postid' => $postid), "{$pid}-{$postid}-{$email}", Net_Gearman_Task::JOB_BACKGROUND); #$task->attachCallback('result'); $set->addTask($task); $client = new Net_Gearman_Client(array('localhost:37003')); $client->runSet($set); print 1;
public function addTask(Net_Gearman_Task $task) { $this->set->addTask($task); $this->submitTask($task); }
protected function create_gearman_set($queries, $table, $complete_cb = null, $failure_cb = null, &$set, $action = "store_resultset", &$state) { if ($this->async) { $task_type = Net_Gearman_task::JOB_BACKGROUND; $query_id = $state->query_id; } else { $task_type = Net_Gearman_task::JOB_NORMAL; $query_id = null; } $sets = array(); if (!$set) { $set = new Net_Gearman_Set(); } if (isset($state->force_shard) && !empty($state->force_shard)) { $shards = $state->force_shard; } else { $shards = $state->shards; } $this->create_agg_table($state); for ($i = 0; $i < count($queries); ++$i) { foreach ($shards as $shard) { $task = new Net_Gearman_Task("store_resultset", array('engine' => $state->engine, 'table_name' => $table, 'sql' => $queries[$i], 'coord_odku' => $state->coord_odku, 'shard' => $shard, 'tmp_shard' => $state->tmp_shard, 'agg_key_cols' => $state->agg_key_cols, 'when' => microtime(true), 'action' => $action, 'query_id' => $query_id), uniqid(md5($queries[$i]), true), $task_type); $task->attachCallback($complete_cb); $task->attachCallback($failure_cb, Net_Gearman_Task::TASK_FAIL); $set->addTask($task); $state->store_resultset_count++; } $sets[] = $set; } return $sets; }
/** * Fire off a background task with the given arguments * * @param string $func Name of job to run * @param array $args First key should be args to send * * @return void * @see Net_Gearman_Task, Net_Gearman_Set */ public function __call($func, array $args = array()) { $send = ""; if (isset($args[0]) && !empty($args[0])) { $send = $args[0]; } $task = new Net_Gearman_Task($func, $send); $task->type = Net_Gearman_Task::JOB_BACKGROUND; $set = new Net_Gearman_Set(); $set->addTask($task); $this->runSet($set); return $task->handle; }
/** * Fire off a background task with the given arguments * * @param string $func Name of job to run * @param array $args First key should be args to send * @param func * @param send */ public function call($func, $send) { $task = new Net_Gearman_Task($func, $send); $task->type = Net_Gearman_Task::JOB_BACKGROUND; $set = new Net_Gearman_Set(); $set->addTask($task); $this->runSet($set); return $task->handle; }
/** * See that task has handle and server assigned. * * @return void */ public function testTaskStatus() { $client = new Net_Gearman_Client(); $task = new Net_Gearman_Task('Reverse', range(1, 5)); $task->type = Net_Gearman_Task::JOB_BACKGROUND; $set = new Net_Gearman_Set(); $set->addTask($task); $client->runSet($set); $this->assertNotEquals('', $task->handle); $this->assertNotEquals('', $task->server); }
protected function create_gearman_set($jobs) { $task_type = Net_Gearman_task::JOB_BACKGROUND; $set = new Net_Gearman_Set(); foreach ($jobs as $job) { #don't bother attaching callbacks since it is a background job $task = new Net_Gearman_Task("loader", $job, md5(serialize($job)), $task_type); $set->addTask($task); } return $set; }
/** * Fire off a background task with the given arguments * * @param string $func Name of job to run * @param array $args Arguments for for the magic method call * First element is the job args. * Second element is an optional task type * @param integer $type Type of job to run task as * * @return mixed For background tasks, the task object is returned. * For foreground tasks, the result is returned. * * @see Net_Gearman_Task */ public function __call($func, array $args) { if (!isset($args[0])) { throw new Net_Gearman_Exception('Invalid job arguments'); } $job_args = $args[0]; if (isset($args[1])) { $type = $args[1]; } else { $type = Net_Gearman_Task::JOB_BACKGROUND; } $task = new Net_Gearman_Task($func, $job_args, null, $type); $set = new Net_Gearman_Set(); $set->addTask($task); $this->runSet($set); if ($type == Net_Gearman_Task::JOB_BACKGROUND || $type == Net_Gearman_Task::JOB_HIGH_BACKGROUND || $type == Net_Gearman_Task::JOB_LOW_BACKGROUND) { $return = $task; } else { $return = $task->result; } return $return; }