public static function get_user_logged_in() { if (isset($_SESSION['user'])) { $user_id = $_SESSION['user']; $user = worker::find($user_id); return $user; } return null; }
public static function handle_login() { $params = $_POST; $user = worker::authenticate($params['name'], $params['password']); if (!$user) { View::make('/login.html', array('error' => 'Väärä käyttäjätunnus tai salasana!', 'name' => $params['name'])); } else { $_SESSION['user'] = $user->id; Redirect::to('/', array('message' => 'Tervetuloa takaisin ' . $user->name . '!')); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { require_once '/vendor/workerman/workerman/Autoloader.php'; $http_worker = new Worker("websocket://0.0.0.0:2345"); $http_worker->count = 4; $http_worker->onConnect = function ($connection) { $connection->send('id' . $connection->id); }; $http_worker->onWorkerStart = function ($worker) { // 定时,每10秒一次 \Workerman\Lib\Timer::add(2, function () use($worker) { // 遍历当前进程所有的客户端连接,发送当前服务器的时间 foreach ($worker->connections as $connection) { $connection->send(time()); } }); }; $http_worker->onMessage = function ($connection, $data) { $connection->send('hello world' . $data); }; worker::runAll(); }
/** * Provides access to the protected method. */ public function create_directory_precheck($path) { return parent::create_directory_precheck($path); }
file_put_contents("./timeout_data.txt", $request['url'] . "\n", FILE_APPEND); } else { file_put_contents("./html/" . $username . ".json", json_encode($data)); } } }; for ($i = 0; $i < 1; $i++) { $username = get_user_queue(); $username = addslashes($username); $url = "http://www.zhihu.com/people/{$username}/about"; $curl->get($url); echo $url . "\r\n"; } $data = $curl->execute(); exit; $w = new worker(); $w->count = 10; $w->is_once = true; $w->log_show = false; $count = 100; // 每个进程循环多少次 $w->on_worker_start = function ($worker) use($count) { //echo $worker->worker_pid . " --- " . $worker->worker_id."\n"; $cookie = trim(file_get_contents("cookie.txt")); $curl = new rolling_curl(); $curl->set_cookie($cookie); $curl->set_gzip(true); $curl->callback = function ($response, $info, $request, $error) { preg_match("@http://www.zhihu.com/people/(.*?)/about@i", $request['url'], $out); $username = $out[1]; if (empty($response)) {
public function loadAllworkersInConflict() { global $logger; $workersInConflict = $mongoworkersInConflict = null; $logger->debug("Selecting collection: conflictworkers"); $this->mongo->selectCollection('conflictworkers'); $mongoworkersInConflict = $this->mongo->find(array()); foreach ($mongoworkersInConflict as $mongoworkerInConflict) { $workersInConflict[] = worker::deserialize($mongoworkerInConflict); } return $workersInConflict; }
/** * Provides access to the protected method. */ public function remove_directory($path, $keeppathroot = false) { return parent::remove_directory($path, $keeppathroot); }
/** * 创建一个子进程 * @param Worker $worker * @throws Exception */ public function fork_one_worker() { //$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $pid = pcntl_fork(); // 父进程,$pid 是子进程的id if ($pid > 0) { self::$_worker_pids[$pid] = $pid; } elseif (0 === $pid) { $this->set_process_title($this->title); $this->set_process_user($this->user); self::$_worker_pids = array(); //$this->uninstall_signal(); $pid = posix_getpid(); //echo "worker[".$pid."] running\n"; if ($this->on_worker_start) { call_user_func($this->on_worker_start, $this); } // 这里用0表示正常退出 exit(0); } else { exit("fork one worker fail"); } }
} public function get_table_data(){ $tdata = array(); foreach($this->pids as $pid){ array_push($tdata,$this->get_row($pid)); } return $tdata; } public function get_with_error(){ return $this->with_error; } } $pivo_staatus = new worker($projects); $status_table = $pivo_staatus->get_table_data(); $with_error = $pivo_staatus->get_with_error(); $pealkiri = Array("Projekti nimi", "Viimase kande pealkiri", "Aeg", "Commiti message", "Aeg", "Acceptimata storyd"); ?> </pre> <?php if($with_error): ?> <h2>Järgmiste isikute Pivotal Trackeri projekti lugemisega tekkis probleem:</h2> <ol> <?php foreach ($with_error as $el): ?> <li><?= $el ?></li> <? endforeach ?> </ol> <?php endif ?>
public function get_env($key) { return parent::get_env($key); }
/** * Default exception handler * * When this handler is used, input_manager and output_manager singleton instances already * exist in the memory and can be used. * * @param Exception $e uncaught exception */ public static function default_exception_handler(Exception $e) { $worker = worker::instance(); $worker->log_exception($e); $output = output_manager::instance(); $output->exception($e); }
<?php if (isset($_GET['theme'])) { $themerequest = $_GET['theme']; } else { $themerequest = "beta_orange"; } if (isset($_GET['page'])) { $website = $_GET['page']; } else { $website = 'Home'; } include_once 'worker.class.php'; $scripts = array("jquery"); $style = "content/style/style.css"; $title = "DrakeWork 0.0.1"; $home = new worker($title, $themerequest, $website, $scripts, $style); echo $home->build_site();
/** * 停止当前worker实例 * 正常运行结束和接受信号退出,都会调用这个方法 * @return void */ public function stop() { if ($this->on_worker_stop) { call_user_func($this->on_worker_stop, $this); } // 设置worker进程的运行状态为关闭 self::$_status = "shutdown"; }