采集网站 相关文件--QueueController.php [ 1.0 版本 ]
YII2网站采集
(1)QueueController.php
(2)ArticleController.php
(3)ArticleJob.php
(4)ArticleSpider.php
(5)YiichinaSpider.php
<?php
namespace console\controllers;
use yii;
class QueueController extends yii\console\Controller{
    /*
     * cd /www/test/advanced/myYii      进入项目目录
     * ps aux|grep yii      查看是否在后台运行  php yii queue/run
     *如果没有后台运行
     * QUEUE=* php yii queue/run &
     * */
    public function actionRun(){
        $QUEUE = getenv('QUEUE');
        if(empty($QUEUE)) {
            die("Set QUEUE env var containing the list of queues to work.\n");
        }
        $REDIS_BACKEND = getenv('REDIS_BACKEND');
        if(!empty($REDIS_BACKEND)) {
            \Resque::setBackend($REDIS_BACKEND);
        }
        $logLevel = 0;
        $LOGGING = getenv('LOGGING');
        $VERBOSE = getenv('VERBOSE');
        $VVERBOSE = getenv('VVERBOSE');
        if(!empty($LOGGING) || !empty($VERBOSE)) {
            $logLevel = \Resque_Worker::LOG_NORMAL;
        }
        else if(!empty($VVERBOSE)) {
            $logLevel = \Resque_Worker::LOG_VERBOSE;
        }
        $APP_INCLUDE = getenv('APP_INCLUDE');
        if($APP_INCLUDE) {
            if(!file_exists($APP_INCLUDE)) {
                die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
            }
            require_once $APP_INCLUDE;
        }
        $interval = 5;
        $INTERVAL = getenv('INTERVAL');
        if(!empty($INTERVAL)) {
            $interval = $INTERVAL;
        }
        $count = 1;
        $COUNT = getenv('COUNT');
        if(!empty($COUNT) && $COUNT > 1) {
            $count = $COUNT;
        }
        if($count > 1) {
            for($i = 0; $i < $count; ++$i) {
                $pid = pcntl_fork();
                if($pid == -1) {
                    die("Could not fork worker ".$i."\n");
                }
                // Child, start the worker
                else if(!$pid) {
                    $queues = explode(',', $QUEUE);
                    $worker = new \Resque_Worker($queues);
                    $worker->logLevel = $logLevel;
                    fwrite(STDOUT, '*** Starting worker '.$worker."\n");
                    $worker->work($interval);
                    break;
                }
            }
        }
        // Start a single worker
        else {
            $queues = explode(',', $QUEUE);
            $worker = new \Resque_Worker($queues);
            $worker->logLevel = $logLevel;
            $PIDFILE = getenv('PIDFILE');
            if ($PIDFILE) {
                file_put_contents($PIDFILE, getmypid()) or
                die('Could not write PID information to ' . $PIDFILE);
            }
            fwrite(STDOUT, '*** Starting worker '.$worker."\n");
            $worker->work($interval);
        }
    }
}
specialnot
            注册时间:2015-08-06
最后登录:2019-08-16
在线时长:27小时54分
    最后登录:2019-08-16
在线时长:27小时54分
- 粉丝43
- 金钱1175
- 威望200
- 积分3445
热门源码
- 整合完 yii2-rbac+yii2-admin+adminlte 等库的基础开发后台源码
- 基于 Yii 2 + Bootstrap 3 搭建一套后台管理系统 CMF
- 适合初学者学习的一款通用的管理后台
- yii-goaop - 将 goaop 集成到 Yii,在 Yii 中优雅的面向切面编程
- yii-log-target - 监控系统异常且多渠道发送异常信息通知
- 店滴云1.3.0
- 面向对象的一小步:添加 ActiveRecord 的 Scope 功能
- Yii2 开源商城 FecShop
- 基于 Yii2 开发的多店铺商城系统,免费开源 + 适合二开
- leadshop - 基于 Yii2 开发的一款免费开源且支持商业使用的商城管理系统


共 1 条评论
Mark!