コード例 #1
0
ファイル: cpWorker.c プロジェクト: WalterShe/php-cp
static void cpManagerReload(int sig)
{
    zval *group_conf = NULL;
    group_conf = cpGetConfig(CPGC.ini_file);
    if (!Z_BVAL_P(group_conf)) {
        cpLog("parse ini file[%s] error,%s reload error!", CPGC.ini_file, CPGC.title);
    } else {
        zval **v, **conf;
        if (zend_hash_find(Z_ARRVAL_P(group_conf), CPGC.title, strlen(CPGC.title) + 1, (void **) &conf) == SUCCESS) {
            if (pthread_mutex_lock(CPGS->mutex_lock) == 0) {
                if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("pool_max"), (void **) &v) == SUCCESS) {
                    convert_to_long(*v);
                    CPGS->worker_max = (int) Z_LVAL_PP(v);
                }
                if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("pool_min"), (void **) &v) == SUCCESS) {
                    convert_to_long(*v);

                    int new_min = (int) Z_LVAL_PP(v);
                    if (new_min > CPGC.worker_min) {//增加最小
                        while (CPGS->worker_num < new_min) {
                            cpCreate_worker_mem(CPGS->worker_num);
                            CPGS->workers_status[CPGS->worker_num] = CP_WORKER_IDLE;
                            CPGS->worker_num++; //先加 线程安全
                            int new_pid = cpFork_one_worker(CPGS->worker_num - 1);
                            if (new_pid < 0) {
                                cpLog("Fork worker process failed. Error: %s [%d]", strerror(errno), errno);
                            } else {
                                CPGS->workers[CPGS->worker_num - 1].pid = new_pid;
                            }
                        }
                    }
                    CPGC.worker_min = new_min;
                }
                if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS) {
                    convert_to_long(*v);
                    CPGC.recycle_num = (int) Z_LVAL_PP(v);
                }
                if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS) {
                    convert_to_long(*v);
                    CPGC.idel_time = (int) Z_LVAL_PP(v);
                }
                if (pthread_mutex_unlock(CPGS->mutex_lock) != 0) {
                    cpLog("pthread_mutex_unlock. Error: %s [%d]", strerror(errno), errno);
                }
            }
        } else {
            cpLog("find %s failed,The reload can only modify 'pool_min','pool_max','recycle_num' and 'idel_time',if you want modify other options please restart pool", CPGC.title);
        }
        zval_ptr_dtor(&group_conf);
    }
}
コード例 #2
0
ファイル: cpWorker.c プロジェクト: caoge/php-cp
static void cpManagerReload(int sig)
{
    zval *group_conf = NULL, **v;
    group_conf = cpGetConfig(CPGC.ini_file);
    int gid = 0;
    zval **gid_ptr = NULL;
    cpGroup *G = NULL;
    if (!Z_BVAL_P(group_conf))
    {
        cpLog("parse ini file[%s]  reload error!", CPGC.ini_file);
    }
    else
    {
        for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(group_conf)); zend_hash_has_more_elements(Z_ARRVAL_P(group_conf)) == SUCCESS; zend_hash_move_forward(Z_ARRVAL_P(group_conf)))
        {
            zval **config;
            zend_hash_get_current_data(Z_ARRVAL_P(group_conf), (void**) &config);
            char *name;
            uint keylen;
            zend_hash_get_current_key_ex(Z_ARRVAL_P(group_conf), &name, &keylen, NULL, 0, NULL);
            if (strcmp(name, "common") != 0)
            {
                if (zend_hash_find(Z_ARRVAL_P(CPGS->group), name, strlen(name) + 1, (void **) &gid_ptr) == SUCCESS)
                {
                    gid = Z_LVAL_PP(gid_ptr);
                    G = &CPGS->G[gid];
                }
                else
                {
                    cpLog("can not add datasource when the server runing,if you want add it please restart");
                    return;
                }
                if (pthread_mutex_lock(G->mutex_lock) == 0)
                {
                    if (zend_hash_find(Z_ARRVAL_PP(config), ZEND_STRS("pool_max"), (void **) &v) == SUCCESS)
                    {
                        convert_to_long(*v);
                        G->worker_max = (int) Z_LVAL_PP(v);
                    }
                    if (zend_hash_find(Z_ARRVAL_PP(config), ZEND_STRS("pool_min"), (void **) &v) == SUCCESS)
                    {
                        convert_to_long(*v);
                        int new_min = (int) Z_LVAL_PP(v);
                        if (new_min > G->worker_min)
                        {//增加最小
                            while (G->worker_num < new_min)
                            {
                                cpCreate_worker_mem(G->worker_num, gid);
                                G->workers_status[G->worker_num] = CP_WORKER_IDLE;
                                G->worker_num++; //先加 线程安全
                                int new_pid = cpFork_one_worker(G->worker_num - 1, gid);
                                if (new_pid < 0)
                                {
                                    cpLog("Fork worker process failed. Error: %s [%d]", strerror(errno), errno);
                                }
                                else
                                {
                                    G->workers[G->worker_num - 1].pid = new_pid;
                                }
                            }
                        }
                        G->worker_min = new_min;
                    }

                    if (pthread_mutex_unlock(G->mutex_lock) != 0)
                    {
                        cpLog("pthread_mutex_unlock. Error: %s [%d]", strerror(errno), errno);
                    }
                }
            }
            else
            {
                if (zend_hash_find(Z_ARRVAL_PP(config), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS)
                {
                    convert_to_long(*v);
                    CPGC.recycle_num = (int) Z_LVAL_PP(v);
                }
                if (zend_hash_find(Z_ARRVAL_PP(config), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS)
                {
                    convert_to_long(*v);
                    CPGC.idel_time = (int) Z_LVAL_PP(v);
                }
            }
        }

        zval_ptr_dtor(&group_conf);
    }
}