static void log_process(zval *send_data, smart_str *buffer) { zval *args = NULL, *method = NULL, *first = NULL; cp_zend_hash_find(Z_ARRVAL_P(send_data), ZEND_STRS("method"), (void **) &method); // snprintf(buffer + strlen(buffer), CLIENT_LOG_BUFFER, "\nmethod:%s\n", Z_STRVAL_P(method)); smart_str_appendl(buffer, "\nmethod:", 8); smart_str_appendl(buffer, Z_STRVAL_P(method), Z_STRLEN_P(method)); cp_zend_hash_find(Z_ARRVAL_P(send_data), ZEND_STRS("args"), (void **) &args); if (cp_zend_hash_index_find(Z_ARRVAL_P(args), 0, (void**) &first) == SUCCESS) { if (Z_TYPE_P(first) == IS_STRING) { smart_str_appendl(buffer, "\nfirst arg:", 11); smart_str_appendl(buffer, Z_STRVAL_P(first), Z_STRLEN_P(first)); } } }
void cpServer_init_common(zval *conf) { zval *v; //daemonize,守护进程化 if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("daemonize"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.daemonize = (int) Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS) //if (cp_zend_hash_find(Z_ARRVAL_P(conf), "recycle_num", strlen("recycle_num"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.recycle_num = (int) Z_LVAL_P(v); } //error_file if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("log_file"), (void **) &v) == SUCCESS) //if (cp_zend_hash_find(Z_ARRVAL_P(conf), "log_file", strlen("log_file"), (void **) &v) == SUCCESS) { memcpy(CPGC.log_file, Z_STRVAL_P(v), Z_STRLEN_P(v)); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_read_len"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.max_read_len = (int) Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("port"), (void **) &v) == SUCCESS) {//todo check null convert_to_long(v); CPGC.port = (int) Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.idel_time = (int) Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("ser_fail_hits"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.ser_fail_hits = (int) Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_fail_num"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.max_fail_num = (int) Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_data_size_to_log"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.max_data_size_to_log = (int) Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_hold_time_to_log"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGC.max_hold_time_to_log = (int) Z_LVAL_P(v); } }
void cpServer_init(zval *conf, char *ini_file) { size_t group_num = 0; cpShareMemory shm = {0}; shm.size = sizeof (cpServerGS); strncpy(shm.mmap_name, CP_SERVER_MMAP_FILE, strlen(CP_SERVER_MMAP_FILE)); if (cp_create_mmap_file(&shm) == 0) { CPGS = (cpServerGS*) cp_mmap_calloc_with_file(&shm); cpKillClient(); bzero(CPGS, shm.size); if (CPGS == NULL) { php_printf("calloc[1] fail\n"); return; } } else { php_printf("calloc[1] fail\n"); return; } bzero(&CPGL, sizeof (cpServerG)); CPGC.backlog = CP_BACKLOG; // CPGC.reactor_num = CP_CPU_NUM; CPGC.reactor_num = 1; CPGC.timeout_sec = CP_REACTOR_TIMEO_SEC; CPGC.timeout_usec = CP_REACTOR_TIMEO_USEC; CPGC.max_conn = CP_MAX_FDS; CPGC.max_request = CP_MAX_REQUEST; CPGC.idel_time = CP_IDEL_TIME; CPGC.recycle_num = CP_RECYCLE_NUM; CPGC.max_read_len = CP_DEF_MAX_READ_LEN; CPGC.ser_fail_hits = 1; CPGC.max_fail_num = 2; CPGC.port = CP_PORT_PDO; CPGC.max_data_size_to_log = 0; CPGC.max_hold_time_to_log = 0; strcpy(CPGC.ini_file, ini_file); // MAKE_STD_ZVAL(CPGS->group); // array_init(CPGS->group); zval *config; char *name; uint32_t klen; int ktype; HashTable *_ht = Z_ARRVAL_P(conf); CP_HASHTABLE_FOREACH_START2(_ht, name, klen, ktype, config) { if (strcmp(name, "common") == 0) {//common config cpServer_init_common(config); } else { zval *v; strcpy(CPGS->G[group_num].name, name); if (cp_zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("pool_min"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGS->G[group_num].worker_num = CPGS->G[group_num].worker_min = Z_LVAL_P(v); } if (cp_zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("pool_max"), (void **) &v) == SUCCESS) { convert_to_long(v); CPGS->G[group_num].worker_max = Z_LVAL_P(v); } CPGS->group_num++; group_num++; } } CP_HASHTABLE_FOREACH_END(); pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); if (pthread_mutex_init(&CPGS->mutex_lock, &attr) < 0) { cpLog("pthread_mutex_init error!. Error: %s [%d]", strerror(errno), errno); return; } CPGS->default_min = CP_DEF_MIN_NUM; CPGS->default_max = CP_DEF_MAX_NUM; CPGS->max_buffer_len = CPGC.max_read_len; CPGS->max_data_size_to_log = CPGC.max_data_size_to_log; CPGS->max_hold_time_to_log = CPGC.max_hold_time_to_log; strcpy(CPGS->log_file, CPGC.log_file); cpServer_init_lock(); }