/* {{{ proto array ImagickPixel::getColorQuantum() Returns the color of the pixel in an array as Quantum values. If ImageMagick was compiled as HDRI these will be floats, otherwise they will be integers */ PHP_METHOD(imagickpixel, getcolorquantum) { php_imagickpixel_object *internp; Quantum red, green, blue, alpha; if (zend_parse_parameters_none() == FAILURE) { return; } internp = Z_IMAGICKPIXEL_P(getThis()); array_init(return_value); red = PixelGetRedQuantum(internp->pixel_wand); green = PixelGetGreenQuantum(internp->pixel_wand); blue = PixelGetBlueQuantum(internp->pixel_wand) ; alpha = PixelGetAlphaQuantum(internp->pixel_wand); #if MAGICKCORE_HDRI_ENABLE add_assoc_double(return_value, "r", red); add_assoc_double(return_value, "g", green); add_assoc_double(return_value, "b", blue); add_assoc_double(return_value, "a", alpha); #else add_assoc_long(return_value, "r", (long)red); add_assoc_long(return_value, "g", (long)green); add_assoc_long(return_value, "b", (long)blue); add_assoc_long(return_value, "a", (long)alpha); #endif return; }
/* {{{ proto array SolrInputDocument::toArray(void) Returns an array representation of the object. */ PHP_METHOD(SolrInputDocument, toArray) { solr_document_t *doc_entry = NULL; zval fields_array; /* Retrieve the document entry for the SolrDocument instance */ if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) { HashTable *fields_ht; array_init(return_value); array_init(&fields_array); zend_hash_init(Z_ARRVAL(fields_array), zend_hash_num_elements(doc_entry->fields), NULL, ZVAL_PTR_DTOR, 0); add_assoc_double(return_value, "document_boost", doc_entry->document_boost); add_assoc_long(return_value, "field_count", doc_entry->field_count); add_assoc_zval(return_value, "fields", &fields_array); fields_ht = doc_entry->fields; SOLR_HASHTABLE_FOR_LOOP(fields_ht) { solr_field_list_t *field = NULL; zval current_field; zval *current_field_ptr = ¤t_field; field = zend_hash_get_current_data_ptr(fields_ht); /* create SolrDocumentField */ solr_create_document_field_object(field, ¤t_field_ptr TSRMLS_CC); /* create SolrDocumentField to the fields HT */ add_next_index_zval(&fields_array, current_field_ptr); } /* We are done */ return; }
/* {{{ proto array accelerator_get_status() Obtain statistics information regarding code acceleration in the Zend Performance Suite */ static ZEND_FUNCTION(accelerator_get_status) { long reqs; zval *memory_usage,*statistics,*scripts; /* keep the compiler happy */ (void)ht; (void)return_value_ptr; (void)this_ptr; (void)return_value_used; if (!ZCG(startup_ok) || !ZCSG(accelerator_enabled)) { RETURN_FALSE; } array_init(return_value); /* Trivia */ add_assoc_bool(return_value, "accelerator_enabled", 1 /*ZCG(startup_ok) && ZCSG(accelerator_enabled)*/); add_assoc_bool(return_value, "cache_full", ZSMMG(memory_exhausted)); /* Memory usage statistics */ MAKE_STD_ZVAL(memory_usage); array_init(memory_usage); add_assoc_long(memory_usage, "used_memory", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory)); add_assoc_long(memory_usage, "free_memory", zend_shared_alloc_get_free_memory()); add_assoc_long(memory_usage, "wasted_memory", ZSMMG(wasted_shared_memory)); add_assoc_double(memory_usage, "current_wasted_percentage", (((double) ZSMMG(wasted_shared_memory))/ZCG(accel_directives).memory_consumption)*100.0); add_assoc_zval(return_value, "memory_usage",memory_usage); /* Accelerator statistics */ MAKE_STD_ZVAL(statistics); array_init(statistics); add_assoc_long(statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries); add_assoc_long(statistics, "max_cached_scripts", ZCSG(hash).max_num_entries); add_assoc_long(statistics, "hits", ZCSG(hits)); add_assoc_long(statistics, "last_restart_time", ZCSG(last_restart_time)); add_assoc_long(statistics, "misses", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses)); add_assoc_long(statistics, "blacklist_misses", ZCSG(blacklist_misses)); reqs = ZCSG(hits)+ZCSG(misses); add_assoc_double(statistics, "blacklist_miss_ratio", reqs?(((double) ZCSG(blacklist_misses))/reqs)*100.0:0); add_assoc_double(statistics, "accelerator_hit_rate", reqs?(((double) ZCSG(hits))/reqs)*100.0:0); add_assoc_zval(return_value, "accelerator_statistics",statistics); /* acceleratred scripts */ scripts=accelerator_get_scripts(TSRMLS_C); if( scripts ){ add_assoc_zval(return_value, "scripts",scripts); } }
/* {{{ proto array accelerator_get_configuration() Obtain configuration information */ static ZEND_FUNCTION(opcache_get_configuration) { zval directives, version, blacklist; if (zend_parse_parameters_none() == FAILURE) { RETURN_FALSE; } if (!validate_api_restriction()) { RETURN_FALSE; } array_init(return_value); /* directives */ array_init(&directives); add_assoc_bool(&directives, "opcache.enable", ZCG(enabled)); add_assoc_bool(&directives, "opcache.enable_cli", ZCG(accel_directives).enable_cli); add_assoc_bool(&directives, "opcache.use_cwd", ZCG(accel_directives).use_cwd); add_assoc_bool(&directives, "opcache.validate_timestamps", ZCG(accel_directives).validate_timestamps); add_assoc_bool(&directives, "opcache.inherited_hack", ZCG(accel_directives).inherited_hack); add_assoc_bool(&directives, "opcache.dups_fix", ZCG(accel_directives).ignore_dups); add_assoc_bool(&directives, "opcache.revalidate_path", ZCG(accel_directives).revalidate_path); add_assoc_long(&directives, "opcache.log_verbosity_level", ZCG(accel_directives).log_verbosity_level); add_assoc_long(&directives, "opcache.memory_consumption", ZCG(accel_directives).memory_consumption); add_assoc_long(&directives, "opcache.interned_strings_buffer",ZCG(accel_directives).interned_strings_buffer); add_assoc_long(&directives, "opcache.max_accelerated_files", ZCG(accel_directives).max_accelerated_files); add_assoc_double(&directives, "opcache.max_wasted_percentage", ZCG(accel_directives).max_wasted_percentage); add_assoc_long(&directives, "opcache.consistency_checks", ZCG(accel_directives).consistency_checks); add_assoc_long(&directives, "opcache.force_restart_timeout", ZCG(accel_directives).force_restart_timeout); add_assoc_long(&directives, "opcache.revalidate_freq", ZCG(accel_directives).revalidate_freq); add_assoc_string(&directives, "opcache.preferred_memory_model", STRING_NOT_NULL(ZCG(accel_directives).memory_model)); add_assoc_string(&directives, "opcache.blacklist_filename", STRING_NOT_NULL(ZCG(accel_directives).user_blacklist_filename)); add_assoc_long(&directives, "opcache.max_file_size", ZCG(accel_directives).max_file_size); add_assoc_string(&directives, "opcache.error_log", STRING_NOT_NULL(ZCG(accel_directives).error_log)); add_assoc_bool(&directives, "opcache.protect_memory", ZCG(accel_directives).protect_memory); add_assoc_bool(&directives, "opcache.save_comments", ZCG(accel_directives).save_comments); add_assoc_bool(&directives, "opcache.load_comments", ZCG(accel_directives).load_comments); add_assoc_bool(&directives, "opcache.fast_shutdown", ZCG(accel_directives).fast_shutdown); add_assoc_bool(&directives, "opcache.enable_file_override", ZCG(accel_directives).file_override_enabled); add_assoc_long(&directives, "opcache.optimization_level", ZCG(accel_directives).optimization_level); add_assoc_zval(return_value, "directives", &directives); /*version */ array_init(&version); add_assoc_string(&version, "version", ACCELERATOR_VERSION); add_assoc_string(&version, "opcache_product_name", ACCELERATOR_PRODUCT_NAME); add_assoc_zval(return_value, "version", &version); /* blacklist */ array_init(&blacklist); zend_accel_blacklist_apply(&accel_blacklist, add_blacklist_path, &blacklist); add_assoc_zval(return_value, "blacklist", &blacklist); }
/* {{{ proto array GmagickPixel::getColor([boolean as_array = false, normalise_array = false]) Returns the color of the pixel */ PHP_METHOD(gmagickpixel, getcolor) { php_gmagickpixel_object *internp; zend_bool as_array = 0, normalise_array = 0; /* Parse parameters given to function */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &as_array, &normalise_array) == FAILURE) { return; } internp = Z_GMAGICKPIXEL_OBJ_P(getThis()); if (!as_array) { char *buffer, *color_string; int len; color_string = PixelGetColorAsString(internp->pixel_wand); len = spprintf(&buffer, 50, "rgb(%s)", color_string); GMAGICK_FREE_MEMORY(char *, color_string); RETVAL_STRINGL(buffer, len); efree(buffer); return; } else { array_init(return_value); if (normalise_array == 1) { add_assoc_double(return_value, "r", PixelGetRed(internp->pixel_wand)); add_assoc_double(return_value, "g", PixelGetGreen(internp->pixel_wand)); add_assoc_double(return_value, "b", PixelGetBlue(internp->pixel_wand)); } else { double red, green, blue; red = PixelGetRed(internp->pixel_wand ) * 255; green = PixelGetGreen(internp->pixel_wand ) * 255; blue = PixelGetBlue(internp->pixel_wand ) * 255; add_assoc_long(return_value, "r", (int)(red > 0.0 ? red + 0.5 : red - 0.5)); add_assoc_long(return_value, "g", (int)(green > 0.0 ? green + 0.5 : green - 0.5)); add_assoc_long(return_value, "b", (int)(blue > 0.0 ? blue + 0.5 : blue - 0.5)); } return; } }
/* {{{ proto array ImagickPixel::getHSL() Returns the normalized HSL color of the pixel wand in an array with the keys "hue", "saturation", and "luminosity". */ PHP_METHOD(imagickpixel, gethsl) { php_imagickpixel_object *internp; double hue, saturation, luminosity; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } internp = (php_imagickpixel_object *)zend_object_store_get_object(getThis() TSRMLS_CC); PixelGetHSL(internp->pixel_wand, &hue, &saturation, &luminosity); array_init(return_value); add_assoc_double(return_value, "hue", hue); add_assoc_double(return_value, "saturation", saturation); add_assoc_double(return_value, "luminosity", luminosity); return; }
/* {{{ proto array ImagickPixel::getHSL() Returns the normalized HSL color of the pixel wand in an array with the keys "hue", "saturation", and "luminosity". */ PHP_METHOD(imagickpixel, gethsl) { php_imagickpixel_object *internp; double hue, saturation, luminosity; if (zend_parse_parameters_none() == FAILURE) { return; } internp = Z_IMAGICKPIXEL_P(getThis()); PixelGetHSL(internp->pixel_wand, &hue, &saturation, &luminosity); array_init(return_value); add_assoc_double(return_value, "hue", hue); add_assoc_double(return_value, "saturation", saturation); add_assoc_double(return_value, "luminosity", luminosity); return; }
/* {{{ proto array ImagickPixel::getColor([bool normalized]) Returns the color of the pixel in an array */ PHP_METHOD(imagickpixel, getcolor) { php_imagickpixel_object *internp; zend_bool normalized = 0; double red, green, blue, alpha; /* Parse parameters given to function */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &normalized) == FAILURE) { return; } internp = (php_imagickpixel_object *)zend_object_store_get_object(getThis() TSRMLS_CC); array_init(return_value); if (normalized == 1) { red = PixelGetRed(internp->pixel_wand); green = PixelGetGreen(internp->pixel_wand); blue = PixelGetBlue(internp->pixel_wand); alpha = PixelGetAlpha(internp->pixel_wand); add_assoc_double(return_value, "r", red); add_assoc_double(return_value, "g", green); add_assoc_double(return_value, "b", blue); add_assoc_double(return_value, "a", alpha); } else { /* TODO: should this be quantum range instead of hardcoded 255.. */ red = PixelGetRed(internp->pixel_wand ) * 255; green = PixelGetGreen(internp->pixel_wand ) * 255; blue = PixelGetBlue(internp->pixel_wand ) * 255; alpha = PixelGetAlpha(internp->pixel_wand); add_assoc_long(return_value, "r", (int)(red > 0.0 ? red + 0.5 : red - 0.5)); add_assoc_long(return_value, "g", (int)(green > 0.0 ? green + 0.5 : green - 0.5)); add_assoc_long(return_value, "b", (int)(blue > 0.0 ? blue + 0.5 : blue - 0.5)); add_assoc_long(return_value, "a", alpha); } return; }
void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray, const char *key) { if (value->IsNull() || value->IsUndefined()) { add_assoc_null(phpArray, (char *) key); } else if (value->IsBool()) { if (value->ToBool()) add_assoc_bool(phpArray, (char *) key, 1); else add_assoc_bool(phpArray, (char *) key, 0); } else if (value->IsNumber()) { /* No way to check whether the number is an integer or a double here. All Kroll numbers are doubles, so return a double. This could cause some PHP to function incorrectly if it's doing strict type checking. */ add_assoc_double(phpArray, (char *) key, value->ToNumber()); } else if (value->IsString()) { add_assoc_stringl(phpArray, (char *) key, (char *) value->ToString(), strlen(value->ToString()), 1); } else if (value->IsObject()) { /*TODO: Implement*/ } else if (value->IsMethod()) { /*TODO: Implement*/ } else if (value->IsList()) { zval *phpValue; AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>(); if (!pl.isNull()) phpValue = pl->ToPHP(); else phpValue = PHPUtils::ToPHPValue(value); add_assoc_zval(phpArray, (char *) key, phpValue); } }
//返回array类型 static PHP_FUNCTION(return_array) { zval *sub; //zval *return_value ,此参数已经被定义在zif函数声明里了,要操作返回值时只需要操作此值函数会自动返回这个结果出去 array_init(return_value); // $ret = array(); add_next_index_bool(return_value, 1); // $ret[] = true; add_index_string(return_value, 5, "Hello", 1); // $ret[5] = "Hello"; add_assoc_long(return_value, "a", 42); //$ret["a"] = 42; add_assoc_string(return_value, "c", "d", 1); //$ret["c"] = "d"; //$sub = array() MAKE_STD_ZVAL(sub); array_init(sub); add_assoc_double(sub, "pi", 3.1415926535); //$sub["pi"] = 3.1415926535 add_next_index_zval(return_value, sub); //$ret[] = $sub; }
/* {{{ apc_cache_link_info */ static zval apc_cache_link_info(apc_cache_t *cache, apc_cache_slot_t* p) { zval link; array_init(&link); add_assoc_str(&link, "info", p->key.str); add_assoc_long(&link, "ttl", p->value->ttl); add_assoc_double(&link, "num_hits", (double)p->nhits); add_assoc_long(&link, "mtime", p->key.mtime); add_assoc_long(&link, "creation_time", p->ctime); add_assoc_long(&link, "deletion_time", p->dtime); add_assoc_long(&link, "access_time", p->atime); add_assoc_long(&link, "ref_count", p->value->ref_count); add_assoc_long(&link, "mem_size", p->value->mem_size); return link; }
/* {{{ proto array ImagickPixel::getColor([int normalization]) Returns the color of the pixel in an array normalization - 0 - values returned in the range 0,255 and will be ints, except for legacy reasons alpha which is 0-1 normalization - 1 - values returned in the range 0,1 and will be floats normalization - 2 - values returned in the range 0,255 and will be ints including alpha values i.e. float if ImageMagick was compiled with HDRI, or integers normally. */ PHP_METHOD(imagickpixel, getcolor) { php_imagickpixel_object *internp; im_long normalization = 0; double red, green, blue, alpha; /* Parse parameters given to function */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &normalization) == FAILURE) { return; } internp = Z_IMAGICKPIXEL_P(getThis()); array_init(return_value); red = PixelGetRed(internp->pixel_wand); green = PixelGetGreen(internp->pixel_wand); blue = PixelGetBlue(internp->pixel_wand); alpha = PixelGetAlpha(internp->pixel_wand); switch (normalization) { //values returned in the range 0,255 and will be ints case(0): { //Leave like this for legacy code //TODO fix the alpha not being normalised at next major/minor verysion red *= 255; green *= 255; blue *= 255; //values are always >=0, so the rounding below may not be necessary add_assoc_long(return_value, "r", (long) (red > 0.0 ? red + 0.5 : red - 0.5)); add_assoc_long(return_value, "g", (long) (green > 0.0 ? green + 0.5 : green - 0.5)); add_assoc_long(return_value, "b", (long) (blue > 0.0 ? blue + 0.5 : blue - 0.5)); add_assoc_long(return_value, "a", alpha); break; } //values returned in the range 0,1 and will be floats case(1): { add_assoc_double(return_value, "r", red); add_assoc_double(return_value, "g", green); add_assoc_double(return_value, "b", blue); add_assoc_double(return_value, "a", alpha); break; } case(2): { red *= 255; green *= 255; blue *= 255; alpha *= 255; //values are always >=0, so the rounding below may not be necessary add_assoc_long(return_value, "r", (long) (red > 0.0 ? red + 0.5 : red - 0.5)); add_assoc_long(return_value, "g", (long) (green > 0.0 ? green + 0.5 : green - 0.5)); add_assoc_long(return_value, "b", (long) (blue > 0.0 ? blue + 0.5 : blue - 0.5)); add_assoc_long(return_value, "a", (long) (alpha > 0.0 ? alpha + 0.5 : alpha - 0.5)); break; } } return; }
/* {{{ proto array accelerator_get_status([bool fetch_scripts]) Obtain statistics information regarding code acceleration */ static ZEND_FUNCTION(opcache_get_status) { long reqs; zval *memory_usage,*statistics,*scripts; zend_bool fetch_scripts = 1; /* keep the compiler happy */ (void)ht; (void)return_value_ptr; (void)this_ptr; (void)return_value_used; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &fetch_scripts) == FAILURE) { return; } if (!accel_startup_ok) { RETURN_FALSE; } array_init(return_value); /* Trivia */ add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled))); add_assoc_bool(return_value, "cache_full", ZSMMG(memory_exhausted)); add_assoc_bool(return_value, "restart_pending", ZCSG(restart_pending)); add_assoc_bool(return_value, "restart_in_progress", ZCSG(restart_in_progress)); /* Memory usage statistics */ MAKE_STD_ZVAL(memory_usage); array_init(memory_usage); add_assoc_long(memory_usage, "used_memory", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory)); add_assoc_long(memory_usage, "free_memory", zend_shared_alloc_get_free_memory()); add_assoc_long(memory_usage, "wasted_memory", ZSMMG(wasted_shared_memory)); add_assoc_double(memory_usage, "current_wasted_percentage", (((double) ZSMMG(wasted_shared_memory))/ZCG(accel_directives).memory_consumption)*100.0); add_assoc_zval(return_value, "memory_usage", memory_usage); /* Accelerator statistics */ MAKE_STD_ZVAL(statistics); array_init(statistics); add_assoc_long(statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries); add_assoc_long(statistics, "num_cached_keys", ZCSG(hash).num_entries); add_assoc_long(statistics, "max_cached_keys", ZCSG(hash).max_num_entries); add_assoc_long(statistics, "hits", ZCSG(hits)); add_assoc_long(statistics, "start_time", ZCSG(start_time)); add_assoc_long(statistics, "last_restart_time", ZCSG(last_restart_time)); add_assoc_long(statistics, "oom_restarts", ZCSG(oom_restarts)); add_assoc_long(statistics, "hash_restarts", ZCSG(hash_restarts)); add_assoc_long(statistics, "manual_restarts", ZCSG(manual_restarts)); add_assoc_long(statistics, "misses", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses)); add_assoc_long(statistics, "blacklist_misses", ZCSG(blacklist_misses)); reqs = ZCSG(hits)+ZCSG(misses); add_assoc_double(statistics, "blacklist_miss_ratio", reqs?(((double) ZCSG(blacklist_misses))/reqs)*100.0:0); add_assoc_double(statistics, "opcache_hit_rate", reqs?(((double) ZCSG(hits))/reqs)*100.0:0); add_assoc_zval(return_value, "opcache_statistics", statistics); if (fetch_scripts) { /* accelerated scripts */ scripts = accelerator_get_scripts(TSRMLS_C); if (scripts) { add_assoc_zval(return_value, "scripts", scripts); } } }
/* {{{ proto array accelerator_get_status([bool fetch_scripts]) Obtain statistics information regarding code acceleration */ static ZEND_FUNCTION(opcache_get_status) { zend_long reqs; zval memory_usage, statistics, scripts; zend_bool fetch_scripts = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &fetch_scripts) == FAILURE) { return; } if (!validate_api_restriction()) { RETURN_FALSE; } if (!accel_startup_ok) { RETURN_FALSE; } array_init(return_value); /* Trivia */ add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled))); #ifdef HAVE_OPCACHE_FILE_CACHE if (ZCG(accel_directives).file_cache) { add_assoc_string(return_value, "file_cache", ZCG(accel_directives).file_cache); } if (ZCG(accel_directives).file_cache_only) { add_assoc_bool(return_value, "file_cache_only", 1); return; } #endif add_assoc_bool(return_value, "cache_full", ZSMMG(memory_exhausted)); add_assoc_bool(return_value, "restart_pending", ZCSG(restart_pending)); add_assoc_bool(return_value, "restart_in_progress", ZCSG(restart_in_progress)); /* Memory usage statistics */ array_init(&memory_usage); add_assoc_long(&memory_usage, "used_memory", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory)); add_assoc_long(&memory_usage, "free_memory", zend_shared_alloc_get_free_memory()); add_assoc_long(&memory_usage, "wasted_memory", ZSMMG(wasted_shared_memory)); add_assoc_double(&memory_usage, "current_wasted_percentage", (((double) ZSMMG(wasted_shared_memory))/ZCG(accel_directives).memory_consumption)*100.0); add_assoc_zval(return_value, "memory_usage", &memory_usage); if (ZCSG(interned_strings_start) && ZCSG(interned_strings_end) && ZCSG(interned_strings_top)) { zval interned_strings_usage; array_init(&interned_strings_usage); add_assoc_long(&interned_strings_usage, "buffer_size", ZCSG(interned_strings_end) - ZCSG(interned_strings_start)); add_assoc_long(&interned_strings_usage, "used_memory", ZCSG(interned_strings_top) - ZCSG(interned_strings_start)); add_assoc_long(&interned_strings_usage, "free_memory", ZCSG(interned_strings_end) - ZCSG(interned_strings_top)); add_assoc_long(&interned_strings_usage, "number_of_strings", ZCSG(interned_strings).nNumOfElements); add_assoc_zval(return_value, "interned_strings_usage", &interned_strings_usage); } /* Accelerator statistics */ array_init(&statistics); add_assoc_long(&statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries); add_assoc_long(&statistics, "num_cached_keys", ZCSG(hash).num_entries); add_assoc_long(&statistics, "max_cached_keys", ZCSG(hash).max_num_entries); add_assoc_long(&statistics, "hits", (zend_long)ZCSG(hits)); add_assoc_long(&statistics, "start_time", ZCSG(start_time)); add_assoc_long(&statistics, "last_restart_time", ZCSG(last_restart_time)); add_assoc_long(&statistics, "oom_restarts", ZCSG(oom_restarts)); add_assoc_long(&statistics, "hash_restarts", ZCSG(hash_restarts)); add_assoc_long(&statistics, "manual_restarts", ZCSG(manual_restarts)); add_assoc_long(&statistics, "misses", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses)); add_assoc_long(&statistics, "blacklist_misses", ZCSG(blacklist_misses)); reqs = ZCSG(hits)+ZCSG(misses); add_assoc_double(&statistics, "blacklist_miss_ratio", reqs?(((double) ZCSG(blacklist_misses))/reqs)*100.0:0); add_assoc_double(&statistics, "opcache_hit_rate", reqs?(((double) ZCSG(hits))/reqs)*100.0:0); add_assoc_zval(return_value, "opcache_statistics", &statistics); if (fetch_scripts) { /* accelerated scripts */ if (accelerator_get_scripts(&scripts)) { add_assoc_zval(return_value, "scripts", &scripts); } } }
void sfixed64_php (zval* out, const char* idx, uint64_t val) { add_assoc_double(out, (char*)idx, (double)val); }
void fixed32_php (zval* out, const char* idx, uint32_t val) { add_assoc_double(out, (char*)idx, (double)val); }
/* {{{ apc_cache_info */ PHP_APCU_API zval apc_cache_info(apc_cache_t* cache, zend_bool limited) { zval info; zval list; zval gc; zval slots; apc_cache_slot_t* p; zend_ulong i, j; if (!cache) { ZVAL_NULL(&info); return info; } /* read lock header */ APC_RLOCK(cache->header); array_init(&info); add_assoc_long(&info, "num_slots", cache->nslots); add_assoc_long(&info, "ttl", cache->ttl); add_assoc_double(&info, "num_hits", (double)cache->header->nhits); add_assoc_double(&info, "num_misses", (double)cache->header->nmisses); add_assoc_double(&info, "num_inserts", (double)cache->header->ninserts); add_assoc_long(&info, "num_entries", cache->header->nentries); add_assoc_double(&info, "expunges", (double)cache->header->nexpunges); add_assoc_long(&info, "start_time", cache->header->stime); add_assoc_double(&info, "mem_size", (double)cache->header->mem_size); #if APC_MMAP add_assoc_stringl(&info, "memory_type", "mmap", sizeof("mmap")-1); #else add_assoc_stringl(&info, "memory_type", "IPC shared", sizeof("IPC shared")-1); #endif if (!limited) { /* For each hashtable slot */ array_init(&list); array_init(&slots); for (i = 0; i < cache->nslots; i++) { p = cache->slots[i]; j = 0; for (; p != NULL; p = p->next) { zval link = apc_cache_link_info(cache, p); add_next_index_zval(&list, &link); j++; } if(j != 0) { add_index_long(&slots, (ulong)i, j); } } /* For each slot pending deletion */ array_init(&gc); for (p = cache->header->gc; p != NULL; p = p->next) { zval link = apc_cache_link_info(cache, p); add_next_index_zval(&gc, &link); } add_assoc_zval(&info, "cache_list", &list); add_assoc_zval(&info, "deleted_list", &gc); add_assoc_zval(&info, "slot_distribution", &slots); } /* unlock header */ APC_RUNLOCK(cache->header); return info; }
static int add_double(zval* list, char* id, double num) { if(id) return add_assoc_double(list, id, num); else return add_next_index_double(list, num); }