static PHP_METHOD(swoole_coroutine_util, stats) { array_init(return_value); sw_add_assoc_long_ex(return_value, ZEND_STRS("stack_size"), COROG.stack_size); sw_add_assoc_long_ex(return_value, ZEND_STRS("coroutine_num"), COROG.coro_num); sw_add_assoc_long_ex(return_value, ZEND_STRS("coroutine_peak_num"), COROG.peak_coro_num); }
zval * yee_exception_to_array_recursive(zval *self, zval *exception) { zend_object *object = (zend_object *)zend_object_store_get_object(self TSRMLS_CC); zend_object *except_object = (zend_object *)zend_object_store_get_object(exception TSRMLS_CC); zval *array; zval *name = NULL, *message = NULL, *code = NULL, *previous = NULL, *previous2 = NULL; MAKE_STD_ZVAL(array); array_init_size(array, 5); if (instanceof_function(except_object->ce, yee_ce_Exception)) { zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getname"), &name, 0, NULL, NULL); }else { MAKE_STD_ZVAL(name); ZVAL_STRING(name, "Exception", 1); } zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getmessage"), &message, 0, NULL, NULL); zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getcode"), &code, 0, NULL, NULL); zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getprevious"), &previous, 0, NULL, NULL); add_assoc_string_ex(array, ZEND_STRS("type"), (char *)except_object->ce->name, 1); add_assoc_zval_ex(array, ZEND_STRS("name"), name); add_assoc_zval_ex(array, ZEND_STRS("message"), message); add_assoc_zval_ex(array, ZEND_STRS("code"), code); if (previous && previous->type == IS_OBJECT) { previous2 = yee_exception_to_array_recursive(self, previous); add_assoc_zval_ex(array, ZEND_STRS("previous"), previous2); } zval_dtor(previous); efree(previous); return array; }
/* {{{ proto ProtocolBuffers\EnumDescriptor ProtocolBuffersDescriptorBuilder::build() */ PHP_METHOD(protocolbuffers_enum_descriptor_builder, build) { zval *result, *container, **fields, **entry, *key, *value; char *property; int property_len; HashPosition pos; MAKE_STD_ZVAL(result); object_init_ex(result, php_protocol_buffers_enum_descriptor_class_entry); MAKE_STD_ZVAL(container); array_init(container); zend_mangle_property_name(&property, &property_len, (char*)"*", 1, (char*)ZEND_STRS("values"), 0); if (zend_hash_find(Z_OBJPROP_P(getThis()), property, property_len, (void **)&fields) == SUCCESS) { zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(fields), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(fields), (void **)&entry, &pos) == SUCCESS) { zval *tmp = NULL; MAKE_STD_ZVAL(tmp); php_protocolbuffers_read_protected_property(*entry, ZEND_STRS("name"), &key TSRMLS_CC); php_protocolbuffers_read_protected_property(*entry, ZEND_STRS("value"), &value TSRMLS_CC); ZVAL_ZVAL(tmp, value, 1, 0); zend_hash_update(Z_ARRVAL_P(container), Z_STRVAL_P(key), Z_STRLEN_P(key), &tmp, sizeof(zval), NULL); zend_hash_move_forward_ex(Z_ARRVAL_PP(fields), &pos); } } efree(property); php_protocolbuffers_set_protected_property(result, ZEND_STRS("values"), container TSRMLS_CC); RETURN_ZVAL(result, 0, 1); }
void air_config_init_default(TSRMLS_D){ zval *_data = NULL; MAKE_STD_ZVAL(_data); array_init(_data); zval *app = NULL; MAKE_STD_ZVAL(app); array_init(app); add_assoc_stringl_ex(app, ZEND_STRS("path"), ZEND_STRL("app"), 1); zval *exec; MAKE_STD_ZVAL(exec); array_init(exec); add_assoc_stringl_ex(exec, ZEND_STRS("path"), ZEND_STRL("exec"), 1); add_assoc_zval_ex(app, ZEND_STRS("exec"), exec); zval *site; MAKE_STD_ZVAL(site); array_init(site); add_assoc_stringl_ex(site, ZEND_STRS("path"), ZEND_STRL("site"), 1); add_assoc_zval_ex(app, ZEND_STRS("site"), site); zval *view; MAKE_STD_ZVAL(view); array_init(view); add_assoc_stringl_ex(view, ZEND_STRS("engine"), ZEND_STRL("air\\view"), 1); add_assoc_stringl_ex(view, ZEND_STRS("path"), ZEND_STRL("view"), 1); add_assoc_stringl_ex(view, ZEND_STRS("type"), ZEND_STRL(".php"), 1); add_assoc_zval_ex(app, ZEND_STRS("view"), view); add_assoc_zval_ex(_data, ZEND_STRS("app"), app); zend_update_static_property(air_config_ce, ZEND_STRL("_data"), _data TSRMLS_CC); zval_ptr_dtor(&_data); }
/* {{{ proto void ProtocolBuffersDescriptorBuilder::addValue(ProtocolBuffers\EnumValueDescriptor $value[, bool $force = false]) */ PHP_METHOD(protocolbuffers_enum_descriptor_builder, addValue) { zval *instance = getThis(); zval *value, **fields, *name; zend_bool force = 0; char *property; int property_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &value, php_protocol_buffers_enum_value_descriptor_class_entry, &force) == FAILURE) { return; } zend_mangle_property_name(&property, &property_len, (char*)"*", 1, (char*)ZEND_STRS("values"), 0); if (zend_hash_find(Z_OBJPROP_P(instance), property, property_len, (void **)&fields) == SUCCESS) { if (php_protocolbuffers_read_protected_property(value, ZEND_STRS("name"), &name TSRMLS_CC)) { if (zend_hash_exists(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name))) { if (force < 1) { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "name `%s` has already registered.", Z_STRVAL_P(name)); } efree(property); return; } } Z_ADDREF_P(value); zend_hash_update(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name)+1, &value, sizeof(zval), NULL); } efree(property); }
PHP_METHOD(air_mysql_waiter, step_2) { AIR_INIT_THIS; zval *services = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_services"), 0 TSRMLS_CC); zval *responses = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_responses"), 0 TSRMLS_CC); zval *context = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_context"), 0 TSRMLS_CC); zval *m2s = air_arr_find(context, ZEND_STRS("m2s")); zval *reads = air_arr_find(context, ZEND_STRS("reads")); zval *waited = air_arr_find(context, ZEND_STRS("waited")); zval *processed = air_arr_find(context, ZEND_STRS("processed")); zval *step = air_arr_find(context, ZEND_STRS("step")); zend_class_entry *mysqli_ce = air_get_ce(ZEND_STRL("mysqli") TSRMLS_CC); ulong idx; char *key; int key_len; zval *mysqli; AIR_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(reads), idx, key, key_len, mysqli){ zval *service_id = air_arr_idx_find(m2s, air_mysqli_get_id(mysqli TSRMLS_CC)); zval *service = air_arr_idx_find(services, Z_LVAL_P(service_id)); zval *mysql = zend_read_property(air_async_service_ce, service, ZEND_STRL("_request"), 0 TSRMLS_CC); zval **trigger_params[2]; zval *event; MAKE_STD_ZVAL(event); zval *event_params; MAKE_STD_ZVAL(event_params); array_init(event_params); Z_ADDREF_P(mysqli); add_next_index_zval(event_params, mysqli); zval *mysqli_result = NULL; if(air_mysqli_get_errno(mysqli TSRMLS_CC)){ ZVAL_STRING(event, "error", 1); }else{ ZVAL_STRING(event, "success", 1); air_call_method(&mysqli, mysqli_ce, NULL, ZEND_STRL("reap_async_query"), &mysqli_result, 0, NULL TSRMLS_CC); Z_ADDREF_P(mysqli_result); add_next_index_zval(event_params, mysqli_result); } trigger_params[0] = &event; trigger_params[1] = &event_params; zval *results = NULL; air_call_method(&mysql, air_mysql_ce, NULL, ZEND_STRL("trigger"), &results, 2, trigger_params TSRMLS_CC); if(results){ add_index_zval(responses, Z_LVAL_P(service_id), results); }else{ php_error(E_WARNING, "error on trigger event %s with no results", Z_STRVAL_P(event)); } zend_hash_index_del(Z_ARRVAL_P(services), Z_LVAL_P(service_id)); zval_ptr_dtor(&event); zval_ptr_dtor(&event_params); if(mysqli_result){ zval_ptr_dtor(&mysqli_result); } zval *mysql_config = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_config"), 0 TSRMLS_CC); zval *mode = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_mode"), 0 TSRMLS_CC); zval **release_params[3] = {&mysqli, &mysql_config, &mode}; air_call_static_method(air_mysql_keeper_ce, "release", NULL, 3, release_params); }AIR_HASH_FOREACH_END();
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); } }
PHP_METHOD(air_mysql_waiter, step_1) { AIR_INIT_THIS; zval *context = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_context"), 0 TSRMLS_CC); zval *wait_pool = air_arr_find(context, ZEND_STRS("pool"));; zval *timeout; MAKE_STD_ZVAL(timeout); ZVAL_LONG(timeout, 0); zend_class_entry *mysqli_ce = air_get_ce(ZEND_STRL("mysqli") TSRMLS_CC); zval *mysqli; zval *errors, *reads, *rejects; MAKE_STD_ZVAL(errors); ZVAL_ZVAL(errors, wait_pool, 1, 0); MAKE_STD_ZVAL(reads); ZVAL_ZVAL(reads, wait_pool, 1, 0); MAKE_STD_ZVAL(rejects); ZVAL_ZVAL(rejects, wait_pool, 1, 0); zval **poll_params[4] = {&reads, &errors, &rejects, &timeout}; zval *count; air_call_static_method(mysqli_ce, "poll", &count, 4, poll_params); if(Z_LVAL_P(count)){ add_assoc_long(context, "step", 2); } add_assoc_zval(context, "reads", reads); zval_ptr_dtor(&errors); zval_ptr_dtor(&rejects); zval_ptr_dtor(&timeout); zval_ptr_dtor(&count); }
/* {{{ locale_register_constants * Register constants common for the both (OO and procedural) * APIs. */ void locale_register_constants( INIT_FUNC_ARGS ) { if( !Locale_ce_ptr ) { zend_error( E_ERROR, "Locale class not defined" ); return; } #define LOCALE_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS) #define LOCALE_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( Locale_ce_ptr, ZEND_STRS( #x ) - 1, ULOC_##x TSRMLS_CC ); #define LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR(name, value) zend_declare_class_constant_string( Locale_ce_ptr, ZEND_STRS( name ) - 1, value TSRMLS_CC ); LOCALE_EXPOSE_CLASS_CONST( ACTUAL_LOCALE ); LOCALE_EXPOSE_CLASS_CONST( VALID_LOCALE ); zend_declare_class_constant_null(Locale_ce_ptr, ZEND_STRS("DEFAULT_LOCALE") - 1 TSRMLS_CC); LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "LANG_TAG", LOC_LANG_TAG); LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "EXTLANG_TAG", LOC_EXTLANG_TAG); LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "SCRIPT_TAG", LOC_SCRIPT_TAG); LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "REGION_TAG", LOC_REGION_TAG); LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "VARIANT_TAG",LOC_VARIANT_TAG); LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "GRANDFATHERED_LANG_TAG",LOC_GRANDFATHERED_LANG_TAG); LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "PRIVATE_TAG",LOC_PRIVATE_TAG); #undef LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR #undef LOCALE_EXPOSE_CLASS_CONST #undef LOCALE_EXPOSE_CONST }
/** * @brief Checks whether @a index exists in array @a arr * @param arr Array * @param index Index * @return isset($arr[$index]) * @retval 0 Not exists, @a arr is not an array or @a index is of not supported type * @retval 1 Exists * @note @c index will be handled as follows: @c NULL is treated as an empty string, @c double values are cast to @c integer, @c bool or @c resource are treated as @c integer * @throw E_WARNING if @a offset is not a scalar */ int ZEPHIR_FASTCALL zephir_array_isset(const zval *arr, zval *index) { HashTable *h; if (Z_TYPE_P(arr) != IS_ARRAY) { return 0; } h = Z_ARRVAL_P(arr); switch (Z_TYPE_P(index)) { case IS_NULL: return zephir_hash_exists(h, ZEND_STRS("")); case IS_DOUBLE: return zend_hash_index_exists(h, (ulong)Z_DVAL_P(index)); case IS_BOOL: case IS_LONG: case IS_RESOURCE: return zend_hash_index_exists(h, Z_LVAL_P(index)); case IS_STRING: return zend_symtable_exists(h, Z_STRVAL_P(index), Z_STRLEN_P(index)+1); default: zend_error(E_WARNING, "Illegal offset type"); return 0; } }
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)); } } }
/* {{{ proto void ProtocolBuffersDescriptorBuilder::__construct() */ PHP_METHOD(protocolbuffers_enum_descriptor_builder, __construct) { zval *fields; MAKE_STD_ZVAL(fields); array_init(fields); php_protocolbuffers_set_protected_property(getThis(), ZEND_STRS("values"), fields TSRMLS_CC); }
/** * @brief Fetches @a index if it exists from the array @a arr * @param[out] fetched <code>&$arr[$index]</code>; @a fetched is modified only when the function returns 1 * @param arr Array * @param index Index * @return isset($arr[$index]) * @retval 0 Not exists, @a arr is not an array or @a index is of not supported type * @retval 1 Exists * @note @c index will be handled as follows: @c NULL is treated as an empty string, @c double values are cast to @c integer, @c bool or @c resource are treated as @c integer * @note $arr[$index] is returned as is: no copying occurs, reference copunt is not updated * @throw E_WARNING if @a offset is not a scalar */ int zephir_array_isset_fetch(zval **fetched, const zval *arr, zval *index, int readonly TSRMLS_DC) { HashTable *h; zval **val; int result; if (Z_TYPE_P(arr) != IS_ARRAY) { *fetched = ZEPHIR_GLOBAL(global_null); if (!readonly) { Z_ADDREF_P(*fetched); } return 0; } h = Z_ARRVAL_P(arr); switch (Z_TYPE_P(index)) { case IS_NULL: result = zephir_hash_find(h, ZEND_STRS(""), (void**)&val); break; case IS_DOUBLE: result = zend_hash_index_find(h, (ulong)Z_DVAL_P(index), (void**)&val); break; case IS_LONG: case IS_BOOL: case IS_RESOURCE: result = zend_hash_index_find(h, Z_LVAL_P(index), (void**)&val); break; case IS_STRING: result = zend_symtable_find(h, (Z_STRLEN_P(index) ? Z_STRVAL_P(index) : ""), Z_STRLEN_P(index)+1, (void**)&val); break; default: zend_error(E_WARNING, "Illegal offset type"); *fetched = ZEPHIR_GLOBAL(global_null); if (!readonly) { Z_ADDREF_P(*fetched); } return 0; } if (result == SUCCESS) { *fetched = *val; if (!readonly) { Z_ADDREF_P(*fetched); } return 1; } *fetched = ZEPHIR_GLOBAL(global_null); if (!readonly) { Z_ADDREF_P(*fetched); } return 0; }
bool ssdb_geo_get( SSDBSock *ssdb_sock, char *key, int key_len, char *member_key, int member_key_len, INTERNAL_FUNCTION_PARAMETERS) { double latlong[2] = {0}; if (!ssdb_geo_member(ssdb_sock, key, key_len, member_key, member_key_len, (double *)latlong)) { return false; } array_init(return_value); add_assoc_double_ex(return_value, ZEND_STRS("latitude"), latlong[0]); add_assoc_double_ex(return_value, ZEND_STRS("longitude"), latlong[1]); return true; }
static int php_memc_sess_lock(memcached_st *memc, const char *key) { char *lock_key = NULL; int lock_key_len = 0; unsigned long attempts; long write_retry_attempts = 0; long lock_maxwait = MEMC_G(sess_lock_max_wait); long lock_wait = MEMC_G(sess_lock_wait); long lock_expire = MEMC_G(sess_lock_expire); time_t expiration; memcached_return status; /* set max timeout for session_start = max_execution_time. (c) Andrei Darashenka, Richter & Poweleit GmbH */ if (lock_maxwait <= 0) { lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0); if (lock_maxwait <= 0) { lock_maxwait = MEMC_SESS_LOCK_EXPIRATION; } } if (lock_wait == 0) { lock_wait = MEMC_SESS_DEFAULT_LOCK_WAIT; } if (lock_expire <= 0) { lock_expire = lock_maxwait; } expiration = lock_expire + 1; attempts = (unsigned long)((1000000.0 / lock_wait) * lock_maxwait); /* Set the number of write retry attempts to the number of replicas times the number of attempts to remove a server */ if (MEMC_G(sess_remove_failed_enabled)) { write_retry_attempts = MEMC_G(sess_number_of_replicas) * ( memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT) + 1); } lock_key_len = spprintf(&lock_key, 0, "lock.%s", key); do { status = memcached_add(memc, lock_key, lock_key_len, "1", sizeof("1")-1, expiration, 0); if (status == MEMCACHED_SUCCESS) { MEMC_G(sess_locked) = 1; MEMC_G(sess_lock_key) = lock_key; MEMC_G(sess_lock_key_len) = lock_key_len; return 0; } else if (status != MEMCACHED_NOTSTORED && status != MEMCACHED_DATA_EXISTS) { if (write_retry_attempts > 0) { write_retry_attempts--; continue; } php_error_docref(NULL, E_WARNING, "Write of lock failed"); break; } if (lock_wait > 0) { usleep(lock_wait); } } while(--attempts > 0); efree(lock_key); return -1; }
/* module helper function */ static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */ { typedef struct { const char *prefix; zend_uchar (*getsize)(); const char *(*get)(zend_uchar i); } xc_nameinfo_t; xc_nameinfo_t nameinfos[] = { { "", xc_get_op_type_count, xc_get_op_type }, { "", xc_get_data_type_count, xc_get_data_type }, { "", xc_get_opcode_count, xc_get_opcode }, { "OPSPEC_", xc_get_op_spec_count, xc_get_op_spec }, { NULL, NULL, NULL } }; int undefdone = 0; xc_nameinfo_t *p; for (p = nameinfos; p->getsize; p ++) { zend_uchar i, count; char const_name[96]; int const_name_len; count = p->getsize(); for (i = 0; i < count; i ++) { const char *name = p->get(i); if (!name) continue; if (strcmp(name, "UNDEF") == 0) { if (undefdone) continue; undefdone = 1; } const_name_len = snprintf(const_name, sizeof(const_name), "XC_%s%s", p->prefix, name); zend_register_long_constant(const_name, const_name_len+1, i, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); } } zend_register_long_constant(ZEND_STRS("XC_SIZEOF_TEMP_VARIABLE"), sizeof(temp_variable), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); zend_register_stringl_constant(ZEND_STRS("XCACHE_VERSION"), ZEND_STRL(XCACHE_VERSION), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); zend_register_stringl_constant(ZEND_STRS("XCACHE_MODULES"), ZEND_STRL(XCACHE_MODULES), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); return 0; }
void cpServer_init_common(zval *conf) { zval **v; //daemonize,守护进程化 if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("daemonize"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.daemonize = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.recycle_num = (int) Z_LVAL_PP(v); } //error_file if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("log_file"), (void **) &v) == SUCCESS) { memcpy(CPGC.log_file, Z_STRVAL_PP(v), Z_STRLEN_PP(v)); } if (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_PP(v); } if (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_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.idel_time = (int) Z_LVAL_PP(v); } if (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_PP(v); } if (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_PP(v); } }
static PHP_METHOD(swoole_process, statQueue) { swWorker *process = swoole_get_object(getThis()); if (!process->queue) { swoole_php_fatal_error(E_WARNING, "have not msgqueue, can not use push()"); RETURN_FALSE; } int queue_num = -1; int queue_bytes = -1; if (swMsgQueue_stat(process->queue, &queue_num, &queue_bytes) == 0) { array_init(return_value); sw_add_assoc_long_ex(return_value, ZEND_STRS("queue_num"), queue_num); sw_add_assoc_long_ex(return_value, ZEND_STRS("queue_bytes"), queue_bytes); } else { RETURN_FALSE; } }
int air_mysql_keeper_get_mysqli(zval **pp_mysqli, zval *config, int mode TSRMLS_DC){ zval *mysqli = air_new_object(ZEND_STRL("mysqli") TSRMLS_CC); air_call_method(&mysqli, Z_OBJCE_P(mysqli), NULL, ZEND_STRL("init"), NULL, 0, NULL TSRMLS_CC); zval **params[7]; zval *host, *user, *pass, *db, *port, *sock, *flag, *nil; MAKE_STD_ZVAL(nil); ZVAL_NULL(nil); zval *auth = air_arr_find(config, ZEND_STRS("auth")); zval *mode_auth = air_arr_idx_find(auth, mode); user = air_arr_find(mode_auth, ZEND_STRS("username")); pass = air_arr_find(mode_auth, ZEND_STRS("password")); params[1] = user? &user: &nil; params[2] = pass? &pass: &nil; params[3] = &nil; MAKE_STD_ZVAL(flag); ZVAL_LONG(flag, MYSQLI_FOUND_ROWS); params[6] = &flag; zval *pool = air_arr_find(config, ZEND_STRS("pool")); zval *mode_pool = air_arr_idx_find(pool, mode); zval *rand_arr[1] = {mode_pool}; zval *mode_hps; zval *ret; while(1){ zval *arr_idx = air_call_func("array_rand", 1, rand_arr); if(!arr_idx){ return -3; } mode_hps = air_arr_idx_find(mode_pool, Z_LVAL_P(arr_idx)); host = air_arr_find(mode_hps, ZEND_STRS("host")); port = air_arr_find(mode_hps, ZEND_STRS("port")); sock = air_arr_find(mode_hps, ZEND_STRS("sock")); params[0] = host? &host: &nil; params[4] = port? &port: &nil; params[5] = sock? &sock: &nil; air_call_method(&mysqli, Z_OBJCE_P(mysqli), NULL, ZEND_STRL("real_connect"), &ret, 7, params TSRMLS_CC); if(Z_LVAL_P(ret)){ zval_ptr_dtor(&arr_idx); zval_ptr_dtor(&ret); break; }else{ zval_ptr_dtor(&ret); zend_hash_index_del(Z_ARRVAL_P(mode_pool), Z_LVAL_P(arr_idx)); zval_ptr_dtor(&arr_idx); if(!zend_hash_num_elements(Z_ARRVAL_P(mode_pool))){ return -5; } } } zval_ptr_dtor(&nil); zval_ptr_dtor(&flag); *pp_mysqli = mysqli; return 0; }
void swoole_process_init(int module_number TSRMLS_DC) { INIT_CLASS_ENTRY(swoole_process_ce, "swoole_process", swoole_process_methods); swoole_process_class_entry_ptr = zend_register_internal_class(&swoole_process_ce TSRMLS_CC); /** * 31 signal constants */ zval *zpcntl; if (sw_zend_hash_find(&module_registry, ZEND_STRS("pcntl"), (void **) &zpcntl) == FAILURE) { REGISTER_LONG_CONSTANT("SIGHUP", (long) SIGHUP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGINT", (long) SIGINT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGQUIT", (long) SIGQUIT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGILL", (long) SIGILL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGTRAP", (long) SIGTRAP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGABRT", (long) SIGABRT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGBUS", (long) SIGBUS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGFPE", (long) SIGFPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGKILL", (long) SIGKILL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGUSR1", (long) SIGUSR1, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGSEGV", (long) SIGSEGV, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGUSR2", (long) SIGUSR2, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGPIPE", (long) SIGPIPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGALRM", (long) SIGALRM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGTERM", (long) SIGTERM, CONST_CS | CONST_PERSISTENT); #ifdef SIGSTKFLT REGISTER_LONG_CONSTANT("SIGSTKFLT", (long) SIGSTKFLT, CONST_CS | CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("SIGCHLD", (long) SIGCHLD, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGCONT", (long) SIGCONT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGSTOP", (long) SIGSTOP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGTSTP", (long) SIGTSTP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGTTIN", (long) SIGTTIN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGTTOU", (long) SIGTTOU, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGURG", (long) SIGURG, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGXCPU", (long) SIGXCPU, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGXFSZ", (long) SIGXFSZ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGVTALRM", (long) SIGVTALRM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGPROF", (long) SIGPROF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGWINCH", (long) SIGWINCH, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SIGIO", (long) SIGIO, CONST_CS | CONST_PERSISTENT); #ifdef SIGPWR REGISTER_LONG_CONSTANT("SIGPWR", (long) SIGPWR, CONST_CS | CONST_PERSISTENT); #endif #ifdef SIGSYS REGISTER_LONG_CONSTANT("SIGSYS", (long) SIGSYS, CONST_CS | CONST_PERSISTENT); #endif } }
static int websocket_handshake(swListenPort *port, http_context *ctx) { #if PHP_MAJOR_VERSION < 7 TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); #endif zval *header = ctx->request.zheader; HashTable *ht = Z_ARRVAL_P(header); zval *pData; if (sw_zend_hash_find(ht, ZEND_STRS("sec-websocket-key"), (void **) &pData) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "header no sec-websocket-key"); return SW_ERR; } convert_to_string(pData); swString_clear(swoole_http_buffer); swString_append_ptr(swoole_http_buffer, ZEND_STRL("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n")); int n; char sec_websocket_accept[128]; memcpy(sec_websocket_accept, Z_STRVAL_P(pData), Z_STRLEN_P(pData)); memcpy(sec_websocket_accept + Z_STRLEN_P(pData), SW_WEBSOCKET_GUID, sizeof(SW_WEBSOCKET_GUID) - 1); char sha1_str[20]; bzero(sha1_str, sizeof(sha1_str)); php_swoole_sha1(sec_websocket_accept, Z_STRLEN_P(pData) + sizeof(SW_WEBSOCKET_GUID) - 1, (unsigned char *) sha1_str); char encoded_str[50]; bzero(encoded_str, sizeof(encoded_str)); n = swBase64_encode((unsigned char *) sha1_str, sizeof(sha1_str), encoded_str); char _buf[128]; n = snprintf(_buf, sizeof(_buf), "Sec-WebSocket-Accept: %*s\r\n", n, encoded_str); swString_append_ptr(swoole_http_buffer, _buf, n); swString_append_ptr(swoole_http_buffer, ZEND_STRL("Sec-WebSocket-Version: "SW_WEBSOCKET_VERSION"\r\n")); if (port->websocket_subprotocol) { swString_append_ptr(swoole_http_buffer, ZEND_STRL("Sec-WebSocket-Protocol: ")); swString_append_ptr(swoole_http_buffer, port->websocket_subprotocol, port->websocket_subprotocol_length); swString_append_ptr(swoole_http_buffer, ZEND_STRL("\r\n")); } swString_append_ptr(swoole_http_buffer, ZEND_STRL("Server: "SW_WEBSOCKET_SERVER_SOFTWARE"\r\n\r\n")); swTrace("websocket header len:%ld\n%s \n", swoole_http_buffer->length, swoole_http_buffer->str); return swServer_tcp_send(SwooleG.serv, ctx->fd, swoole_http_buffer->str, swoole_http_buffer->length); }
static int websocket_handshake(http_client *client) { //HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: %s\r\nSec-WebSocket-Version: %s\r\nKeepAlive: off\r\nContent-Length: 0\r\nServer: ZWebSocket\r\n TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); zval *header = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("header"), 1 TSRMLS_CC); HashTable *ht = Z_ARRVAL_P(header); zval **pData; if(zend_hash_find(ht, ZEND_STRS("sec-websocket-key") , (void **) &pData) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "header no sec-websocket-key"); return SW_ERR; } convert_to_string(*pData); // swTrace("key: %s len:%d\n", Z_STRVAL_PP(pData), Z_STRLEN_PP(pData)); swString *buf = swString_new(256); swString_append_ptr(buf, ZEND_STRL("HTTP/1.1 101 Switching Protocols\r\n")); swString_append_ptr(buf, ZEND_STRL("Upgrade: websocket\r\nConnection: Upgrade\r\n")); swString *shaBuf = swString_new(Z_STRLEN_PP(pData)+36); swString_append_ptr(shaBuf, Z_STRVAL_PP(pData), Z_STRLEN_PP(pData)); swString_append_ptr(shaBuf, ZEND_STRL(SW_WEBSOCKET_GUID)); char data_str[20]; // bzero(data_str, sizeof(data_str)); // swTrace("sha1 start:%s\n", shaBuf->str); sha1(shaBuf->str, (unsigned char *) data_str); char encoded_value[50]; bzero(encoded_value, sizeof(encoded_value)); // swTrace("base64_encode start:%d\n", sizeof(data_str)); swBase64_encode((unsigned char *) data_str, 20, encoded_value); // swTrace("base64_encode end:%s %d %d\n", encoded_value, encoded_len, strlen(encoded_value)); char _buf[128]; int n = 0; n = snprintf(_buf, strlen(encoded_value)+25, "Sec-WebSocket-Accept: %s\r\n", encoded_value); // efree(data_str); // efree(encoded_value); swString_free(shaBuf); // swTrace("accept value: %s\n", _buf); swString_append_ptr(buf, _buf, n); swString_append_ptr(buf, ZEND_STRL("Sec-WebSocket-Version: 13\r\n")); swString_append_ptr(buf, ZEND_STRL("Server: swoole-websocket\r\n\r\n")); swTrace("websocket header len:%zd\n%s \n", buf->length, buf->str); int ret = swServer_tcp_send(SwooleG.serv, client->fd, buf->str, buf->length); swString_free(buf); // swTrace("handshake send: %d lenght: %d\n", client->fd, ret); return ret; }
/* {{{ proto string ProtocolBuffersEnum::getName(long $value) */ PHP_METHOD(protocolbuffers_enum, getName) { #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3) zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getName can't work under PHP 5.3. please consider upgrading your PHP"); return; #else long value; zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &value) == FAILURE) { return; } if (zend_call_method_with_0_params(NULL, EG(called_scope), NULL, "getenumdescriptor", &result)) { zval *values, **entry; HashPosition pos; if (!instanceof_function_ex(Z_OBJCE_P(result), php_protocol_buffers_enum_descriptor_class_entry, 0 TSRMLS_CC)) { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getEnumDescriptor returns unexpected value."); zval_ptr_dtor(&result); return; } php_protocolbuffers_read_protected_property(result, ZEND_STRS("values"), &values TSRMLS_CC); zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&entry, &pos) == SUCCESS) { if (Z_LVAL_PP(entry) == value) { char *key; uint key_len; ulong index; zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &key, &key_len, &index, 0, &pos); RETURN_STRINGL(key, key_len, 1); break; } zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos); } zval_ptr_dtor(&result); RETVAL_FALSE; } else { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "cannot call ProtocolBuffersEnum::getEnumDescriptor."); return; } #endif }
zval * request_query(int type, char * name, int len TSRMLS_DC) { zval **carrier, **ret; switch (type) { case TRACK_VARS_POST: case TRACK_VARS_GET: case TRACK_VARS_FILES: case TRACK_VARS_COOKIE: carrier = &PG(http_globals)[type]; break; case TRACK_VARS_ENV: carrier = &PG(http_globals)[type]; break; case TRACK_VARS_SERVER: carrier = &PG(http_globals)[type]; break; case TRACK_VARS_REQUEST: (void) zend_hash_find(&EG(symbol_table), ZEND_STRS("_REQUEST"), (void **) &carrier); break; default: break; } if (!carrier || !(*carrier)) { zval *empty; MAKE_STD_ZVAL(empty); ZVAL_NULL(empty); return empty; } if (!len) { Z_ADDREF_P(*carrier); return *carrier; } if (zend_hash_find(Z_ARRVAL_PP(carrier), name, len + 1, (void **) &ret) == FAILURE) { zval *empty; MAKE_STD_ZVAL(empty); ZVAL_NULL(empty); return empty; } Z_ADDREF_P(*ret); return *ret; }
PHP_METHOD(pdo_connect_pool_PDOStatement, __call) { zval *z_args; zval *object; zval *pass_data; zval **zres, **source_zval; char *cmd; int cmd_len; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa", &object, pdo_connect_pool_PDOStatement_class_entry_ptr, &cmd, &cmd_len, &z_args) == FAILURE) { RETURN_FALSE; } cpClient *cli; if (zend_hash_find(Z_OBJPROP_P(getThis()), ZEND_STRS("cli"), (void **) &zres) == SUCCESS) { ZEND_FETCH_RESOURCE(cli, cpClient*, zres, -1, CP_RES_CLIENT_NAME, le_cli_connect_pool); } else {
static void release_worker(zval *object) { zend_rsrc_list_entry *p_sock_le; zval **data_source; if (zend_hash_find(Z_OBJPROP_P(object), ZEND_STRS("data_source"), (void **) &data_source) == SUCCESS) { if (zend_hash_find(&EG(persistent_list), Z_STRVAL_PP(data_source), Z_STRLEN_PP(data_source), (void **) &p_sock_le) == SUCCESS) { send_oob2proxy(p_sock_le); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "p_sock_le can not find"); } } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "data_source can not find"); } }
static void release_worker(zval *object) { zend_rsrc_list_entry *p_sock_le; zval **pool_port; if (zend_hash_find(Z_OBJPROP_P(object), ZEND_STRS("pool_port"), (void **) &pool_port) == SUCCESS) { char str[100] = {0}; CON_FORMART_KEY(str, (int) Z_LVAL_PP(pool_port)); if (zend_hash_find(&EG(persistent_list), str, strlen(str), (void **) &p_sock_le) == SUCCESS) { send_oob2proxy(p_sock_le); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "p_sock_le can not find"); } } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "pool_port can not find"); } }
/** {{{ Mylogs::err */ PHP_METHOD(Mylogs, err) { char *msg; int msg_len; zval *instance, *level, **_level; zend_class_entry *ce; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &msg, &msg_len) == FAILURE) return; instance = _getInstance(); ce = Z_OBJCE_P(instance); level = zend_read_property(mylogs_ce, instance, ZEND_STRL(MYLOGS_LEVEL), 0 TSRMLS_CC); zend_hash_find(&ce->constants_table, ZEND_STRS(LOG_ERR), (void **)&_level); if(Z_LVAL_P(level) > Z_LVAL_PP(_level)) { RETURN_TRUE; } if(_log(msg) == SUCCESS) { RETURN_TRUE; } RETURN_FALSE; }
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); } }
PHP_METHOD(air_view, render){ AIR_INIT_THIS; char *tpl_str; int tpl_len = 0; zend_bool ret_res = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sb", &tpl_str, &tpl_len, &ret_res) == FAILURE) { RETURN_FALSE; } smart_str ss_path = {0}; if(tpl_str[0] != '/'){ zval *root_path = NULL; MAKE_STD_ZVAL(root_path); if(zend_get_constant(ZEND_STRL("ROOT_PATH"), root_path) == FAILURE){ php_error_docref(NULL TSRMLS_CC, E_ERROR, "ROOT_PATH not defined"); } smart_str_appendl(&ss_path, Z_STRVAL_P(root_path), Z_STRLEN_P(root_path)); smart_str_appendc(&ss_path, '/'); if(root_path != NULL){ zval_ptr_dtor(&root_path); } zval *tmp = NULL; zval **tmp_pp; zval *config = zend_read_property(air_view_ce, getThis(), ZEND_STRL("_config"), 0 TSRMLS_CC); if(config != NULL && Z_TYPE_P(config) == IS_ARRAY && zend_hash_find(Z_ARRVAL_P(config), ZEND_STRL("path"), (void **)&tmp_pp) == SUCCESS){ smart_str_appendl(&ss_path, Z_STRVAL_PP(tmp_pp), Z_STRLEN_PP(tmp_pp)); }else{ zval *app_conf; zval *view_conf; if(air_config_get(NULL, ZEND_STRS("app"), &app_conf TSRMLS_CC) == FAILURE){ AIR_NEW_EXCEPTION(1, "@error config: app"); } zval *app_path = NULL; if(air_config_get(app_conf, ZEND_STRS("path"), &app_path) == FAILURE){ AIR_NEW_EXCEPTION(1, "@error config: app.path"); } zval *view_path = NULL; if(air_config_get_path(app_conf, ZEND_STRS("view.path"), &view_path) == FAILURE){ AIR_NEW_EXCEPTION(1, "@view config not found"); } smart_str_appendl(&ss_path, Z_STRVAL_P(app_path), Z_STRLEN_P(app_path)); smart_str_appendc(&ss_path, '/'); smart_str_appendl(&ss_path, Z_STRVAL_P(view_path), Z_STRLEN_P(view_path)); } smart_str_appendc(&ss_path, '/'); } smart_str_appendl(&ss_path, tpl_str, tpl_len); smart_str_0(&ss_path); //php_printf("full view path: %s\n", ss_path.c); //构造运行时所需基本变量 HashTable *origin_symbol_table = NULL; zval *output_handler = NULL; long chunk_size = 0; long flags = PHP_OUTPUT_HANDLER_STDFLAGS; zval *view_ret = NULL; //尝试缓存当前符号表 if(EG(active_symbol_table)){ origin_symbol_table = EG(active_symbol_table); } if (ret_res) { MAKE_STD_ZVAL(view_ret); if(php_output_start_user(output_handler, chunk_size, flags TSRMLS_CC) == FAILURE) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to create buffer"); RETURN_FALSE; } } ALLOC_HASHTABLE(EG(active_symbol_table)); zval *data = zend_read_property(air_view_ce, getThis(), ZEND_STRL("_data"), 0 TSRMLS_CC); zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0); //将当前的模板变量放到符号表去 ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), "var", 4, data, Z_REFCOUNT_P(data) + 1, PZVAL_IS_REF(data)); if(air_loader_include_file(ss_path.c TSRMLS_CC) == FAILURE){ air_throw_exception_ex(1, "tpl %s render failed!\n", ss_path.c); return ; } if(ret_res){ php_output_get_contents(view_ret TSRMLS_CC); php_output_discard(TSRMLS_C); RETVAL_ZVAL(view_ret, 1, 0); zval_ptr_dtor(&view_ret); } zend_hash_destroy(EG(active_symbol_table)); FREE_HASHTABLE(EG(active_symbol_table)); EG(active_symbol_table) = origin_symbol_table; smart_str_free(&ss_path); }