Req #61277 [Nab]: Feature request: Shared Keyword

From: Date: Mon, 05 Mar 2012 02:26:09 +0000
Subject: Req #61277 [Nab]: Feature request: Shared Keyword
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-168120@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61277&edit=1

 ID:                 61277
 User updated by:    thbley at gmail dot com
 Reported by:        thbley at gmail dot com
 Summary:            Feature request: Shared Keyword
 Status:             Not a bug
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   All
 PHP Version:        5.5.0
 Block user comment: N
 Private report:     N

 New Comment:

> It is a design decision in PHP not to have such global things in PHP itself.

All PHP frameworks are offering some kind of caching with shared disk or shared memory. And I
haven't seen a bigger project not using this stuff. It's time to rethink this decision.

> - correct locking can be hard

I think the way APC does this it, should do it.

> - such a feature makes scaling over multiple servers hard

It would be enough to have it on one server. For those who want more, can still send the data to
memcache.

Here is a new example: https://gist.github.com/1975954


Previous Comments:
------------------------------------------------------------------------
[2012-03-05 00:19:10] johannes@php.net

It is a design decision in PHP not to have such global things in PHP itself. Addon modules (you
mentioned apc) can add utilities for this, though.

Some reasons include: 
- PHP can be embedded in any application which might add constrains
- correct locking can be hard
- such a feature makes scaling over multiple servers hard
- it messes with copy-on-write
- ...

------------------------------------------------------------------------
[2012-03-04 20:29:34] thbley at gmail dot com

update version :-)

------------------------------------------------------------------------
[2012-03-04 20:28:49] thbley at gmail dot com

Description:
------------
Feature request: Shared Keyword

Declaring class properties as shared makes them accessible for all instances of a PHP script
containing the same class name and the same property name.
This functionality allows a shared memory access similar to apc_store() and apc_fetch().

The shared property implies the static property.
Shared propertes can be accessed without needing an instantiation of the class.
If shared is not set for a property, it will be non-shared by default.
Shared properties are accessed through the class name or a class name variable or "self",
and the Scope Resolution Operator "::".
Like any other PHP static variable, shared properties may only be initialized using a literal or
constant; expressions are not allowed.
So while you may initialize a shared property to an integer or array (for instance), you may not
initialize it to another variable, to a function return value, or to an object.

Shared memory limit in php.ini:
shared_memory_limit = 16M

This sets the maximum amount of shared memory in bytes that ALL scripts are allowed to allocate.
To have no shared memory limit, set this directive to -1.
To have an unlimited shared memory limit, set this directive to 0.
When an integer is used, the value is measured in bytes. Shorthand notation may also be used.

Shared variables and properties are initialized only in first call of a function/class and every
time the shared memory is empty.

Scenarios: Caching, performance optimization, counters, progress indicators, parallel queues, etc.

Test script:
---------------
Foo.php: static class property
<?
class Foo
{
    shared $cache_shared = "hello"; // public static shared

    private shared $_cache_shared = "hello"; // private static shared

    protected shared $_cache_shared = "hello"; // protected static shared

    shared static $cache_static_shared = "hello"; // invalid, shared implies static

    $var1 = "hello"; // public non-static non-shared
}


Foo2.php: static variable
<?
function some_big_calc()
{
    shared $a = array();
}


Scenarios:
some_class::$shared_cache = array(...);
some_class::$shared_counter++;
some_class::$shared_progress = 0.3;



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61277&edit=1


Thread (9 messages)

« previous php.bugs (#168120) next »