Exemplo n.º 1
0
PHP_METHOD(MongoDB, repair)
{
	zend_bool cloned=0, original=0;
	zval *cmd, *retval;
	mongo_db *db;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &cloned, &original) == FAILURE) {
		return;
	}

	PHP_MONGO_GET_DB(getThis());

	MAKE_STD_ZVAL(cmd);
	array_init(cmd);
	add_assoc_long(cmd, "repairDatabase", 1);
	add_assoc_bool(cmd, "preserveClonedFilesOnFailure", cloned);
	add_assoc_bool(cmd, "backupOriginalFiles", original);

	retval = php_mongo_runcommand(db->link, &db->read_pref, Z_STRVAL_P(db->name), Z_STRLEN_P(db->name), cmd, NULL, 0, NULL TSRMLS_CC);

	zval_ptr_dtor(&cmd);

	if (retval) {
		RETVAL_ZVAL(retval, 0, 1);
	}
}
Exemplo n.º 2
0
static int full_user_list(struct user_info *uentp, struct fulluserlistarg* arg,int count)
{
    struct user_info userinfo=*uentp;
    struct userec *lookupuser;
    zval* element;
    if (!userinfo.active || !userinfo.pid) {
        return 0;
    }
    if (!HAS_PERM(getCurrentUser(), PERM_SEECLOAK) && userinfo.invisible && strcmp(userinfo.userid, getCurrentUser()->userid)) {
        /*Haohmaru.99.4.24.让隐身者能看见自己 */
        return 0;
    }
    if (count+1<arg->start)
        return COUNT;
    if (count+1-arg->start>=arg->num)
        return QUIT;
    MAKE_STD_ZVAL ( element );
    array_init ( element );

    add_assoc_bool ( element, "invisible", userinfo.invisible );
    add_assoc_long ( element, "pid", userinfo.pid );
    add_assoc_bool ( element, "isfriend", isfriend(userinfo.userid) );
    add_assoc_string ( element, "userid", userinfo.userid, 1 );
    add_assoc_string ( element, "username", userinfo.username, 1 );
    if( getuser(userinfo.userid, &lookupuser) == 0 ) lookupuser=NULL;
    add_assoc_string ( element, "userfrom", HAS_PERM(getCurrentUser(), PERM_SYSOP)? userinfo.from: SHOW_USERIP(lookupuser, userinfo.from), 1 );
    add_assoc_string ( element, "mode", ModeType(userinfo.mode), 1 );
    add_assoc_long ( element, "idle", (long)(time(0) - userinfo.freshtime)/60 );
    
    zend_hash_index_update(Z_ARRVAL_P(arg->return_value), count+1-arg->start, (void *) &element, sizeof(zval *), NULL);
    return COUNT;
}
Exemplo n.º 3
0
/** {{{ public ZeActiveString::update($oldCondition, $newCondition)
 */
PHP_METHOD(ze_activestring, update) {
    zval * self           = NULL;
    zval * actives        = NULL;
    char * old_cond       = NULL;
    int    old_cond_len   = 0;
    char * new_cond       = NULL;
    int    new_cond_len   = 0;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss"
                            , &old_cond, &old_cond_len
                            , &new_cond, &new_cond_len
                            ) == FAILURE) {
        WRONG_PARAM_COUNT;
    }

    self = getThis();

    actives = zend_read_property(ze_activestring_ce, self, ZEND_STRL(ZE_ACTIVES), 0 TSRMLS_CC);

    zend_hash_del(Z_ARRVAL_P(actives), old_cond, old_cond_len + 1);

    add_assoc_bool(actives, new_cond, 1);

    zend_update_property(ze_activestring_ce, self, ZEND_STRL(ZE_ACTIVES), actives TSRMLS_CC);

    RETURN_ZVAL(self, 1, 0);
}
Exemplo n.º 4
0
/* {{{ MongoCursor->getCursorInfo: Return information about the current query (by @crodas)
 */
PHP_METHOD(MongoCursor, info)
{
  mongo_cursor *cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC);
  MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor);
  array_init(return_value);

  add_assoc_string(return_value, "ns", cursor->ns, 1);
  add_assoc_long(return_value, "limit", cursor->limit);
  add_assoc_long(return_value, "batchSize", cursor->batch_size);
  add_assoc_long(return_value, "skip", cursor->skip);
  if (cursor->query) {
    add_assoc_zval(return_value, "query", cursor->query);
    zval_add_ref(&cursor->query);
  } else {
    add_assoc_null(return_value, "query");
  }
  if (cursor->fields) {
    add_assoc_zval(return_value, "fields", cursor->fields);
    zval_add_ref(&cursor->fields);
  } else {
    add_assoc_null(return_value, "fields");
  }
    
  add_assoc_bool(return_value, "started_iterating", cursor->started_iterating);
  if (cursor->started_iterating) {
    add_assoc_long(return_value, "id", (long)cursor->cursor_id);
    add_assoc_long(return_value, "at", cursor->at);
    add_assoc_long(return_value, "numReturned", cursor->num);
    add_assoc_string(return_value, "server", cursor->server->label, 1);
  }
}
Exemplo n.º 5
0
/* {{{ proto array tidy_get_config()
   Get current Tidy configuration */
static PHP_FUNCTION(tidy_get_config)
{
	TidyIterator itOpt;
	char *opt_name;
	void *opt_value;
	TidyOptionType optt;

	TIDY_FETCH_OBJECT;

	itOpt = tidyGetOptionList(obj->ptdoc->doc);

	array_init(return_value);

	while (itOpt) {
		TidyOption opt = tidyGetNextOption(obj->ptdoc->doc, &itOpt);

		opt_name = (char *)tidyOptGetName(opt);
		opt_value = php_tidy_get_opt_val(obj->ptdoc, opt, &optt);
		switch (optt) {
			case TidyString:
				add_assoc_str(return_value, opt_name, (zend_string*)opt_value);
				break;

			case TidyInteger:
				add_assoc_long(return_value, opt_name, (zend_long)opt_value);
				break;

			case TidyBoolean:
				add_assoc_bool(return_value, opt_name, opt_value ? 1 : 0);
				break;
		}
	}

	return;
}
Exemplo n.º 6
0
void CACHE_BASE::serialize_php(zval *zbaselist, bool everything)
{
  CACHE_COLL *cc;
  zval *zbase, *zcolllist;
	MAKE_STD_ZVAL(zbase);
	array_init(zbase);
	add_assoc_long(zbase, (char *)"base_id", this->base_id);
	add_assoc_long(zbase, (char *)"sbas_id", this->sbas_id);
	add_assoc_bool(zbase, (char *)"online", this->online);
	add_assoc_string(zbase, (char *)"viewname", this->viewname, true);
	add_assoc_string(zbase, (char *)"host", this->host, true);
	add_assoc_long(zbase, (char *)"port", this->port);
	add_assoc_string(zbase, (char *)"user", this->user, true);
	add_assoc_string(zbase, (char *)"passwd", this->passwd, true);
	add_assoc_long(zbase, (char *)"engine", this->engine);
	add_assoc_string(zbase, (char *)"dbname", this->dbname, true);
	if(this->xmlstruct)
		add_assoc_string(zbase, (char *)"xmlstruct", this->xmlstruct, true);

	MAKE_STD_ZVAL(zcolllist);
	array_init(zcolllist);
	for(cc = this->firstcoll; cc; cc = cc->nextcoll)
	{
		if(everything || cc->registered)		// on ne retourne pas les collections (bases) sur lesquelles on n'est pas registered
			cc->serialize_php(zcolllist);
	}
	add_assoc_zval(zbase, (char *)"collections", zcolllist);
	add_next_index_zval(zbaselist, zbase);
}
/* {{{ 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);
	}
}
Exemplo n.º 8
0
Arquivo: db.cpp Projeto: 191919/hhvm
PHP_METHOD(MongoDB, createCollection)
{
	zval *data = NULL, *temp, *options = NULL;
	char *collection;
	int   collection_len;
	zend_bool capped = 0;
	long size = 0, max = 0;

	if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s|bll", &collection, &collection_len, &capped, &size, &max) == SUCCESS) {
		MAKE_STD_ZVAL(data);
		array_init(data);

		add_assoc_stringl(data, "create", collection, collection_len, 1);

		if (size) {
			add_assoc_long(data, "size", size);
		}

		if (capped) {
			php_error_docref(NULL TSRMLS_CC, MONGO_E_DEPRECATED, "This method now accepts arguments as an options array instead of the three optional arguments for capped, size and max elements");
			add_assoc_bool(data, "capped", 1);
			if (max) {
				add_assoc_long(data, "max", max);
			}
		}

	} else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &collection, &collection_len, &options) == SUCCESS) {
		zval *tmp_copy;

		/* We create a new array here, instead of just tagging "create" =>
		 * <name> at the end of the array. This is because MongoDB wants the
		 * name of the command as first element in the array. */
		MAKE_STD_ZVAL(data);
		array_init(data);
		add_assoc_stringl(data, "create", collection, collection_len, 1);
		if (options) {
			zend_hash_merge(Z_ARRVAL_P(data), Z_ARRVAL_P(options), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0);
		}
	} else {

		return;
	}

	MAKE_STD_ZVAL(temp);
	MONGO_METHOD1(MongoDB, command, temp, getThis(), data);
	zval_ptr_dtor(&temp);

	zval_ptr_dtor(&data);

	if (!EG(exception)) {
		zval *zcollection;

		/* get the collection we just created */
		MAKE_STD_ZVAL(zcollection);
		ZVAL_STRINGL(zcollection, collection, collection_len, 1);
		MONGO_METHOD1(MongoDB, selectCollection, return_value, getThis(), zcollection);
		zval_ptr_dtor(&zcollection);
	}
}
Exemplo n.º 9
0
    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);
        }
    }
Exemplo n.º 10
0
PHP_METHOD(MongoDB, repair) {
  zend_bool cloned=0, original=0;
  zval *data;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &cloned, &original) == FAILURE) {
    return;
  }

  MAKE_STD_ZVAL(data);
  array_init(data);
  add_assoc_long(data, "repairDatabase", 1);
  add_assoc_bool(data, "preserveClonedFilesOnFailure", cloned);
  add_assoc_bool(data, "backupOriginalFiles", original);

  MONGO_CMD(return_value, getThis());

  zval_ptr_dtor(&data);
}
Exemplo n.º 11
0
/* {{{ MongoCursor->explain
 */
PHP_METHOD(MongoCursor, explain) {
  zval *query;
  mongo_cursor *cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC);
  MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor);

  query = cursor->query;
  add_assoc_bool(query, "$explain", 1);

  MONGO_METHOD(MongoCursor, reset)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
  MONGO_METHOD(MongoCursor, getNext)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
Exemplo n.º 12
0
static void add_expr_to_array(zval *expressions, uri_template_expr *expr)
{
	uri_template_var *next;
	zval *result;
	zval *vars;
	char op[2] = {expr->op, 0};
	char sep[2] = {expr->sep, 0};
	char ifemp[2] = {expr->ifemp, 0};
	
	MAKE_STD_ZVAL(result);
	array_init(result);
	
	add_assoc_string(result, "op", op, 1);
	add_assoc_string(result, "sep", sep, 1);
	add_assoc_string(result, "ifemp", ifemp, 1);
	add_assoc_bool(result, "allow", expr->allow);
	add_assoc_bool(result, "named", expr->named);
	add_assoc_bool(result, "error", expr->error);
	
	MAKE_STD_ZVAL(vars);
	array_init_size(vars, expr->vars->count);
	
	next = expr->vars->first;
	
	while (next != NULL) {
		zval *var;
		
		MAKE_STD_ZVAL(var);
		array_init(var);
		
		add_assoc_string(var, "name", next->name, 1);
		add_assoc_long(var, "length", next->length);
		add_assoc_bool(var, "explode", next->explode);
		add_next_index_zval(vars, var);
		
		next = next->next;
	}
	
	add_assoc_zval(result, "vars", vars);
	add_next_index_zval(expressions, result);
}
Exemplo n.º 13
0
/* {{{ php_parsekit_parse_arginfo */
static void php_parsekit_parse_arginfo(zval *return_value, zend_uint num_args, zend_arg_info *arginfo, long options TSRMLS_DC)
{
	zend_uint i;

	array_init(return_value);

	for(i = 0; i < num_args; i++) {
		zval *tmpzval;

		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_stringl(tmpzval, "name", arginfo[i].name, arginfo[i].name_len, 1);
		if (arginfo[i].class_name_len) {
			add_assoc_stringl(tmpzval, "class_name", arginfo[i].class_name, arginfo[i].class_name_len, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(tmpzval, "class_name");
		}
		add_assoc_bool(tmpzval, "allow_null", arginfo[i].allow_null);
		add_assoc_bool(tmpzval, "pass_by_reference", arginfo[i].pass_by_reference);

		add_next_index_zval(return_value, tmpzval);
	}	
}
Exemplo n.º 14
0
/* {{{ META_API void meta_token_zval_ex(TOKEN*, zval*)
 * create an array representation of token into the preallocated tok_repr */
META_API void meta_token_zval_ex(TOKEN *token, zval *tok_repr) {
    array_init_size(tok_repr, 8);/* 8 inwhich allow this to happenstead of 5, so zend_hash_init doesn't need to round up */
    add_assoc_long(tok_repr, "major", token->major);
    add_assoc_bool(tok_repr, "dirty", token->dirty);
    add_assoc_long(tok_repr, "start_line", token->start_line);
    add_assoc_long(tok_repr, "end_line", token->end_line);
    if(NULL != TOKEN_MINOR(token)) {
        //zval_add_ref(&token->minor);
        add_assoc_zval(tok_repr, "minor", token->minor);
    }
    else {
        add_assoc_null(tok_repr, "minor");
    }
}
Exemplo n.º 15
0
Arquivo: jam.c Projeto: brzuchal/jam
static void php_jam_user_event_trigger(int type TSRMLS_DC, const char *error_filename, const uint error_lineno, const char *format, ...)
{
	zval *event;
	va_list args;

	ALLOC_INIT_ZVAL(event);
	array_init(event);
	
	add_assoc_bool(event, "jam_event_trigger", 1);
	
	va_start(args, format);
	php_jam_capture_error_ex(event, type, error_filename, error_lineno, 1, format, args TSRMLS_CC);
	va_end(args);
}
Exemplo n.º 16
0
/** {{{ proto Win\Gdi\DeviceContext Win\Gdi\Window::beginPaint(array & paint_data)
		Prepares the specified window for painting. The paint_data reference variable
		receives information about the painting.
*/
PHP_METHOD( WinGdiWindow, beginPaint )
{
	wingdi_devicecontext_object * dc_object,
								* dc_object_display;
	wingdi_window_object        * window_object = zend_object_store_get_object( getThis() TSRMLS_CC );
	zval                        * paint_data, 
	                            * paint_data_rect = NULL,
								* paint_data_hdc  = NULL;
	PAINTSTRUCT                   paint_struct;
	HDC                           hdc;

	WINGDI_ERROR_HANDLING();
	if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "z", &paint_data ) == FAILURE )
		return;
	WINGDI_RESTORE_ERRORS();

	hdc = BeginPaint( window_object->window_handle, &paint_struct );
	if ( !hdc )
	{
		wingdi_create_error( GetLastError(), ce_wingdi_exception TSRMLS_CC );
		return;
	}

	// Set up return value for a DC object
	object_init_ex( return_value, ce_wingdi_devicecontext );
	dc_object = ( wingdi_devicecontext_object * ) zend_objects_get_address( return_value TSRMLS_CC );
	dc_object->hdc = hdc;
	dc_object->constructed = 1;

	// Empty whatever the paint_data zval contains, and store in it the data from paint_struct
	zval_dtor( paint_data );
	array_init( paint_data );
	// Set up the hdc element object
	MAKE_STD_ZVAL( paint_data_hdc );
	object_init_ex( paint_data_hdc, ce_wingdi_devicecontext );
	dc_object_display = ( wingdi_devicecontext_object * ) zend_objects_get_address( paint_data_hdc TSRMLS_CC );
	dc_object_display->hdc = paint_struct.hdc;
	dc_object_display->constructed = 1;
	add_assoc_zval( paint_data, "hdc",   paint_data_hdc );
	add_assoc_bool( paint_data, "erase", paint_struct.fErase );
	// paint_struct.rcPaint is a RECT structure which maps to a PHP array
	MAKE_STD_ZVAL( paint_data_rect );
	array_init( paint_data_rect );
	add_next_index_long( paint_data_rect, paint_struct.rcPaint.left );
	add_next_index_long( paint_data_rect, paint_struct.rcPaint.top );
	add_next_index_long( paint_data_rect, paint_struct.rcPaint.right );
	add_next_index_long( paint_data_rect, paint_struct.rcPaint.bottom );
	add_assoc_zval( paint_data, "paint", paint_data_rect );
}
Exemplo n.º 17
0
/* {{{ MongoCursor::snapshot
 */
PHP_METHOD(MongoCursor, snapshot) {
  zval *query;
  mongo_cursor *cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC);
  MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor);

  if (cursor->started_iterating) {
    zend_throw_exception(mongo_ce_CursorException, "cannot modify cursor after beginning iteration.", 0 TSRMLS_CC);
    return;
  }

  query = cursor->query;
  add_assoc_bool(query, "$snapshot", 1);

  RETURN_ZVAL(getThis(), 1, 0);
}
Exemplo n.º 18
0
void CACHE_COLL::serialize_php(zval *zcolllist)
{
  zval *zcoll;
	MAKE_STD_ZVAL(zcoll);
	array_init(zcoll);
	add_assoc_long(zcoll, (char *)"coll_id", this->coll_id);
	add_assoc_long(zcoll, (char *)"base_id", this->base_id);
	add_assoc_string(zcoll, (char *)"name", this->name, true);
#if GETPREFS
	add_assoc_string(zcoll, (char *)"prefs", this->prefs, true);
#endif
	//	add_assoc_string(zcoll, "phserver_host", this->phserver_host, true);
//	add_assoc_long(zcoll, (char *)"phserver_port", this->phserver_port);
	add_assoc_bool(zcoll, (char *)"registered", this->registered);
	add_next_index_zval(zcolllist, zcoll);
}
Exemplo n.º 19
0
/* {{{ META_API zval* meta_token_zval(TOKEN*)
 * Get the zval representation of a token */
META_API zval* meta_token_zval(TOKEN *token) {
    zval* tok_repr;
    MAKE_STD_ZVAL(tok_repr);
    array_init_size(tok_repr, 8);/* 8 instead of 5, so zend_hash_init doesn't need to round up */
    add_assoc_long(tok_repr, "major", token->major);
    add_assoc_bool(tok_repr, "dirty", token->dirty);
    add_assoc_long(tok_repr, "start_line", token->start_line);
    add_assoc_long(tok_repr, "end_line", token->end_line);
    if(NULL != TOKEN_MINOR(token)) {
        zval_add_ref(&token->minor);
        add_assoc_zval(tok_repr, "minor", token->minor);
    }
    else {
        add_assoc_null(tok_repr, "minor");
    }
    return tok_repr;
}
Exemplo n.º 20
0
PHP_METHOD(MongoCollection, validate) {
  zval *data;
  zend_bool scan_data = 0;
  mongo_collection *c;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &scan_data) == FAILURE) {
    return;
  }

  PHP_MONGO_GET_COLLECTION(getThis());

  MAKE_STD_ZVAL(data);
  array_init(data);
  add_assoc_string(data, "validate", Z_STRVAL_P(c->name), 1);
  add_assoc_bool(data, "full", scan_data);

  MONGO_CMD(return_value, c->parent);

  zval_ptr_dtor(&data);
}
Exemplo n.º 21
0
/** {{{ public ZeActiveString::active($condition)
 */
PHP_METHOD(ze_activestring, active) {
    zval * self       = NULL;
    zval * actives    = NULL;
    char * cond       = NULL;
    int    cond_len   = 0;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s"
                            , &cond, &cond_len
                            ) == FAILURE) {
        WRONG_PARAM_COUNT;
    }

    self = getThis();

    actives = zend_read_property(ze_activestring_ce, self, ZEND_STRL(ZE_ACTIVES), 0 TSRMLS_CC);

    add_assoc_bool(actives, cond, 1);

    zend_update_property(ze_activestring_ce, self, ZEND_STRL(ZE_ACTIVES), actives TSRMLS_CC);

    RETURN_ZVAL(self, 1, 0);
}
Exemplo n.º 22
0
PHP_METHOD(MongoDB, createCollection) {
  zval *collection, *data, *temp;
  zend_bool capped=0;
  long size=0, max=0;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|bll", &collection, &capped, &size, &max) == FAILURE) {
    return;
  }

  MAKE_STD_ZVAL(data);
  array_init(data);
  convert_to_string(collection);
  add_assoc_zval(data, "create", collection);
  zval_add_ref(&collection);

  if (size) {
    add_assoc_long(data, "size", size);
  }

  if (capped) {
    add_assoc_bool(data, "capped", 1);
    if (max) {
      add_assoc_long(data, "max", max);
    }
  }

  MAKE_STD_ZVAL(temp);
  MONGO_CMD(temp, getThis());
  zval_ptr_dtor(&temp);

  zval_ptr_dtor(&data);

  if (!EG(exception)) {
    // get the collection we just created
    MONGO_METHOD1(MongoDB, selectCollection, return_value, getThis(), collection);
  }
}
Exemplo n.º 23
0
/* {{{ php_parsekit_derive_arginfo 
	ZE1 Func Arg loading is done via opcodes "RECV"ing from the caller */
static void php_parsekit_derive_arginfo(zval *return_value, zend_op_array *op_array, long options TSRMLS_DC)
{
	int i;
	zend_op *opcodes = op_array->opcodes;

	array_init(return_value);

	/* Received vars come in pairs:
		A ZEND_FETCH_W, and a ZEND_RECV */
	for(i = 0; i < op_array->arg_types[0]; i++) {
		if (opcodes[i*2].opcode   == ZEND_FETCH_W &&
			opcodes[i*2].op1.op_type == IS_CONST &&
			opcodes[i*2].op1.u.constant.type == IS_STRING &&
			(opcodes[(i*2)+1].opcode == ZEND_RECV || opcodes[(i*2)+1].opcode == ZEND_RECV_INIT)) {
			zval *tmpzval;

			MAKE_STD_ZVAL(tmpzval);
			array_init(tmpzval);

			add_assoc_stringl(tmpzval, "name", opcodes[i*2].op1.u.constant.value.str.val, opcodes[i*2].op1.u.constant.value.str.len, 1);
			add_assoc_bool(tmpzval, "pass_by_reference", op_array->arg_types[i+1]);
			if (opcodes[(i*2)+1].opcode == ZEND_RECV_INIT &&
				opcodes[(i*2)+1].op2.op_type == IS_CONST) {
				zval *def;
	
				MAKE_STD_ZVAL(def);
				*def = opcodes[(i*2)+1].op2.u.constant;
				zval_copy_ctor(def);
				add_assoc_zval(tmpzval, "default", def);
				Z_SET_REFCOUNT_P(tmpzval, 1);
			}

			add_next_index_zval(return_value, tmpzval);
		}
	}
}
Exemplo n.º 24
0
static int php_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam)
{
	int oldmode, flags;
	php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
	php_stream_xport_param *xparam;

	if (!sock) {
		return PHP_STREAM_OPTION_RETURN_NOTIMPL;
	}

	switch(option) {
		case PHP_STREAM_OPTION_CHECK_LIVENESS:
			{
				struct timeval tv;
				char buf;
				int alive = 1;

				if (value == -1) {
					if (sock->timeout.tv_sec == -1) {
						tv.tv_sec = FG(default_socket_timeout);
						tv.tv_usec = 0;
					} else {
						tv = sock->timeout;
					}
				} else {
					tv.tv_sec = value;
					tv.tv_usec = 0;
				}

				if (sock->socket == -1) {
					alive = 0;
				} else if (php_pollfd_for(sock->socket, PHP_POLLREADABLE|POLLPRI, &tv) > 0) {
#ifdef PHP_WIN32
					int ret;
#else
					ssize_t ret;
#endif
					int err;

					ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK);
					err = php_socket_errno();
					if (0 == ret || /* the counterpart did properly shutdown*/
						(0 > ret && err != EWOULDBLOCK && err != EAGAIN)) { /* there was an unrecoverable error */
						alive = 0;
					}
				}
				return alive ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
			}

		case PHP_STREAM_OPTION_BLOCKING:
			oldmode = sock->is_blocked;
			if (SUCCESS == php_set_sock_blocking(sock->socket, value)) {
				sock->is_blocked = value;
				return oldmode;
			}
			return PHP_STREAM_OPTION_RETURN_ERR;

		case PHP_STREAM_OPTION_READ_TIMEOUT:
			sock->timeout = *(struct timeval*)ptrparam;
			sock->timeout_event = 0;
			return PHP_STREAM_OPTION_RETURN_OK;

		case PHP_STREAM_OPTION_META_DATA_API:
			add_assoc_bool((zval *)ptrparam, "timed_out", sock->timeout_event);
			add_assoc_bool((zval *)ptrparam, "blocked", sock->is_blocked);
			add_assoc_bool((zval *)ptrparam, "eof", stream->eof);
			return PHP_STREAM_OPTION_RETURN_OK;

		case PHP_STREAM_OPTION_XPORT_API:
			xparam = (php_stream_xport_param *)ptrparam;

			switch (xparam->op) {
				case STREAM_XPORT_OP_LISTEN:
					xparam->outputs.returncode = (listen(sock->socket, xparam->inputs.backlog) == 0) ?  0: -1;
					return PHP_STREAM_OPTION_RETURN_OK;

				case STREAM_XPORT_OP_GET_NAME:
					xparam->outputs.returncode = php_network_get_sock_name(sock->socket,
							xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
							xparam->want_addr ? &xparam->outputs.addr : NULL,
							xparam->want_addr ? &xparam->outputs.addrlen : NULL
							);
					return PHP_STREAM_OPTION_RETURN_OK;

				case STREAM_XPORT_OP_GET_PEER_NAME:
					xparam->outputs.returncode = php_network_get_peer_name(sock->socket,
							xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
							xparam->want_addr ? &xparam->outputs.addr : NULL,
							xparam->want_addr ? &xparam->outputs.addrlen : NULL
							);
					return PHP_STREAM_OPTION_RETURN_OK;

				case STREAM_XPORT_OP_SEND:
					flags = 0;
					if ((xparam->inputs.flags & STREAM_OOB) == STREAM_OOB) {
						flags |= MSG_OOB;
					}
					xparam->outputs.returncode = sock_sendto(sock,
							xparam->inputs.buf, xparam->inputs.buflen,
							flags,
							xparam->inputs.addr,
							xparam->inputs.addrlen);
					if (xparam->outputs.returncode == -1) {
						char *err = php_socket_strerror(php_socket_errno(), NULL, 0);
						php_error_docref(NULL, E_WARNING,
						   	"%s\n", err);
						efree(err);
					}
					return PHP_STREAM_OPTION_RETURN_OK;

				case STREAM_XPORT_OP_RECV:
					flags = 0;
					if ((xparam->inputs.flags & STREAM_OOB) == STREAM_OOB) {
						flags |= MSG_OOB;
					}
					if ((xparam->inputs.flags & STREAM_PEEK) == STREAM_PEEK) {
						flags |= MSG_PEEK;
					}
					xparam->outputs.returncode = sock_recvfrom(sock,
							xparam->inputs.buf, xparam->inputs.buflen,
							flags,
							xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
							xparam->want_addr ? &xparam->outputs.addr : NULL,
							xparam->want_addr ? &xparam->outputs.addrlen : NULL
							);
					return PHP_STREAM_OPTION_RETURN_OK;


#ifdef HAVE_SHUTDOWN
# ifndef SHUT_RD
#  define SHUT_RD 0
# endif
# ifndef SHUT_WR
#  define SHUT_WR 1
# endif
# ifndef SHUT_RDWR
#  define SHUT_RDWR 2
# endif
				case STREAM_XPORT_OP_SHUTDOWN: {
					static const int shutdown_how[] = {SHUT_RD, SHUT_WR, SHUT_RDWR};

					xparam->outputs.returncode = shutdown(sock->socket, shutdown_how[xparam->how]);
					return PHP_STREAM_OPTION_RETURN_OK;
				}
#endif

				default:
					return PHP_STREAM_OPTION_RETURN_NOTIMPL;
			}

		default:
			return PHP_STREAM_OPTION_RETURN_NOTIMPL;
	}
}
Exemplo n.º 25
0
/* {{{ 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.validate_permission", ZCG(accel_directives).validate_permission);
#ifndef ZEND_WIN32
	add_assoc_bool(&directives, "opcache.validate_root",       ZCG(accel_directives).validate_root);
#endif
	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.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);

#ifndef ZEND_WIN32
	add_assoc_string(&directives, "opcache.lockfile_path",          STRING_NOT_NULL(ZCG(accel_directives).lockfile_path));
#endif

#ifdef HAVE_OPCACHE_FILE_CACHE
	add_assoc_string(&directives, "opcache.file_cache",                    ZCG(accel_directives).file_cache ? ZCG(accel_directives).file_cache : "");
	add_assoc_bool(&directives,   "opcache.file_cache_only",               ZCG(accel_directives).file_cache_only);
	add_assoc_bool(&directives,   "opcache.file_cache_consistency_checks", ZCG(accel_directives).file_cache_consistency_checks);
#endif

	add_assoc_zval(return_value, "directives", &directives);

	/*version */
	array_init(&version);
	add_assoc_string(&version, "version", PHP_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);
}
Exemplo n.º 26
0
/* {{{ 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);
		}
	}
}
Exemplo n.º 27
0
void bool_php (zval* out, const char* idx, protobuf_c_boolean val) {
    add_assoc_bool(out, (char*)idx, (int)val);
}
Exemplo n.º 28
0
/* {{{ clm_get_device_info() */
static zval *clm_get_device_info(cl_device_id device TSRMLS_DC)
{
	const device_info_param_t *param = device_info_list;
	cl_int err = CL_SUCCESS;
	char buf[1024] = { 0 };
	size_t len = 0;
	cl_uint max_work_item_dimensions = 0;
	zval *zinfo;

	err = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
	                      sizeof(max_work_item_dimensions),
	                      &max_work_item_dimensions, NULL);
	if (err != CL_SUCCESS) {
		max_work_item_dimensions = 0;
	}

	MAKE_STD_ZVAL(zinfo);
	array_init_size(zinfo, 64);

	while (param->key != NULL) {
		switch (param->type) {
			case PARAM_TYPE_BITFIELD: {
				cl_bitfield val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_BOOL: {
				cl_bool val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					zend_bool bval = (zend_bool)val;
					add_assoc_bool(zinfo, param->key, bval);
				}
			}
			break;

			case PARAM_TYPE_SIZE: {
				size_t val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_UINT: {
				cl_uint val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_ULONG: {
				cl_ulong val = 0;
				err = clGetDeviceInfo(device, param->name, sizeof(val), &val, NULL);
				if (err == CL_SUCCESS) {
					long lval = (long)val;
					add_assoc_long(zinfo, param->key, lval);
				}
			}
			break;

			case PARAM_TYPE_STRING: {
				err = clGetDeviceInfo(device, param->name, sizeof(buf), buf, &len);
				if (err == CL_SUCCESS) {
					add_assoc_stringl(zinfo, param->key, buf, len, 1);
				}
			}
			break;

			case PARAM_TYPE_PLATFORM: {
				cl_platform_id platform;
				err = clGetDeviceInfo(device, param->name, sizeof(platform), &platform, NULL);
				if (err == CL_SUCCESS) {
					zval *pinfo = clm_get_platform_info(platform TSRMLS_CC);
					add_assoc_zval(zinfo, param->key, pinfo);
				}
			}
			break;

			case PARAM_TYPE_MAX_WORK_ITEM_SIZES: {
				size_t siz = sizeof(size_t) * max_work_item_dimensions;
				size_t *sizes = ecalloc(max_work_item_dimensions, sizeof(size_t));
				if (!sizes) {
					break;
				}

				err = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES, siz, sizes, NULL);
				if (err == CL_SUCCESS) {
					cl_uint i;
					zval *zsizes;
					MAKE_STD_ZVAL(zsizes);
					array_init_size(zsizes, max_work_item_dimensions);
					for (i = 0; i < max_work_item_dimensions; i++) {
						long lval = (long)sizes[i];
						add_next_index_long(zsizes, lval);
					}
					add_assoc_zval(zinfo, param->key, zsizes);
				}

				efree(sizes);
			}
			break;
		}

		if (err != CL_SUCCESS) {
			add_assoc_null(zinfo, param->key);
		}

		param++;
	}

	return zinfo;
}
/* {{{ 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);
		}
	}
}
Exemplo n.º 30
0
/* List pure functions */
void ra_init_function_table(RedisArray *ra) {
    array_init(&ra->z_pure_cmds);

    add_assoc_bool(&ra->z_pure_cmds, "HGET", 1);
    add_assoc_bool(&ra->z_pure_cmds, "HGETALL", 1);
    add_assoc_bool(&ra->z_pure_cmds, "HKEYS", 1);
    add_assoc_bool(&ra->z_pure_cmds, "HLEN", 1);
    add_assoc_bool(&ra->z_pure_cmds, "SRANDMEMBER", 1);
    add_assoc_bool(&ra->z_pure_cmds, "HMGET", 1);
    add_assoc_bool(&ra->z_pure_cmds, "STRLEN", 1);
    add_assoc_bool(&ra->z_pure_cmds, "SUNION", 1);
    add_assoc_bool(&ra->z_pure_cmds, "HVALS", 1);
    add_assoc_bool(&ra->z_pure_cmds, "TYPE", 1);
    add_assoc_bool(&ra->z_pure_cmds, "EXISTS", 1);
    add_assoc_bool(&ra->z_pure_cmds, "LINDEX", 1);
    add_assoc_bool(&ra->z_pure_cmds, "SCARD", 1);
    add_assoc_bool(&ra->z_pure_cmds, "LLEN", 1);
    add_assoc_bool(&ra->z_pure_cmds, "SDIFF", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZCARD", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZCOUNT", 1);
    add_assoc_bool(&ra->z_pure_cmds, "LRANGE", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZRANGE", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZRANK", 1);
    add_assoc_bool(&ra->z_pure_cmds, "GET", 1);
    add_assoc_bool(&ra->z_pure_cmds, "GETBIT", 1);
    add_assoc_bool(&ra->z_pure_cmds, "SINTER", 1);
    add_assoc_bool(&ra->z_pure_cmds, "GETRANGE", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZREVRANGE", 1);
    add_assoc_bool(&ra->z_pure_cmds, "SISMEMBER", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZREVRANGEBYSCORE", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZREVRANK", 1);
    add_assoc_bool(&ra->z_pure_cmds, "HEXISTS", 1);
    add_assoc_bool(&ra->z_pure_cmds, "ZSCORE", 1);
    add_assoc_bool(&ra->z_pure_cmds, "HGET", 1);
    add_assoc_bool(&ra->z_pure_cmds, "OBJECT", 1);
    add_assoc_bool(&ra->z_pure_cmds, "SMEMBERS", 1);
}