Re: Could apc_fetch return a pointer to data in shared memory ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Thanks Simon. you got my hopes up there for a second.

>From the php docs page:

>Critics further argue that it is pointless to use a Singleton in a Shared
Nothing Architecture like PHP where objects are unique >within the Request
only anyways.

I want the the singleton class to be global to the entire application (ie
shared "by reference" across all requests). I'd agree with the above
critics that if you have to instantiate your singleton for each request,
it's rather pointless.

On 2 April 2012 07:54, Simon Schick <simonsimcity@xxxxxxxxxxxxxx> wrote:

> 2012/4/1 Simon <slgard@xxxxxxxxx>
> >
> > Another thing that's possible in .NET is the Singleton design pattern.
> > (Application variables are an implementation of this pattern)
> >
> > This makes it possible to instantiate a static class so that a single
> > instance of the object is available to all threads (ie requests) across
> > your application.
> >
> > So for example the code below creates a single instance of an object for
> > the entire "server". Any code calling "new App();"  gets a pointer to the
> > shared object.
> >
> > If PHP could do this, it would be *awesome* and I wouldn't need
> > application
> > variables since this is a superior solution.
> >
> > Can / could PHP do anything like this ?
> >
> > public class App
> > {
> >   private static App instance;
> >   private App() {}
> >   public static App Instance
> >   {
> >      get
> >      {
> >         if (instance == null)
> >         {
> >            instance = new App();
> >         }
> >         return instance;
> >      }
> >   }
> > }
> >
> >
> > Creates an inste
>
> Hi, Simon
>
> Sorry for this out-of-context post - but just to answer to Simon's
> question:
>
> One way of implementing Singleton in PHP is written down in the php-manual:
> http://www.php.net/manual/en/language.oop5.patterns.php
> I personally would also declare __clone() and __wakeup() as private,
> but that's something personal :)
>
> If you have many places where you'd like to use the Singleton-pattern
> you may now think of having one class where you define the pattern
> itself and extending other classes from that ... But that does not
> seem the good way to me because this classes are not related at all,
> in case of content.
> Other frameworks are using interfaces but they have to write the code
> for the implementation over and over again.
>
> Here's where traids make the most sense to me:
>
> http://stackoverflow.com/questions/7104957/building-a-singleton-trait-with-php-5-4
>
> Bye
> Simon
>

[PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [Find Someone]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux