On 31 Mar 2012, at 02:33, Simon wrote:

> Or: Why doesn't PHP have Applications variables like ASP.NET  (and node.js)
> ?
> Hi,
> I'm working on optimising a php application (Drupal).
> The best optimisation I've found so far is to use APC to store various bits
> of Drupal data in RAM.
> The problem with this is that with Drupal requiring say 50Mb of data* per
> request is that lots of cpu cycles are wasted de-serialising data out of
> apc_fetch. Also 50Mb of data per http process !! is wasted by each one
> re-creating it's own copy of the shared data.

50MB? WTF is it storing?? I've never used Drupal, but based purely on that it 
sounds like an extremely inefficient piece of software that's best avoided!

> If it were possible for apc_fetch (or similar function) to return a pointer
> to the data rather than a copy of the data this would enable incredible
> reduction in cpu and memory usage.

Vanilla PHP adheres to a principle known as "shared nothing architecture" in 
which, shockingly, nothing is shared between processes or requests. This is 
primarily for scalability reasons; if you stick to the shared nothing approach 
your application should be easily scalable.

> This is essentially how ASP.NET Application variables and node.js work.

Not a valid comparison. Node.js applications can only share variables within a 
single process, and they can do so because it's single-threaded. Once you scale 
your app beyond a single process you'd need to add a custom layer on to share 
data between them.

I'm not sure about the architecture behind IIS and ASP.net but I imagine there 
are similar paradigms at work.

> I'm surprised PHP doesn't already have Application variables, given that
> they are so similar to Session Variables and that it's been around for a
> long time in ASP / ASP.NET.

Just because x does it, doesn't mean y should. I've used lots of languages over 
the years, including classic ASP, ASP.net, Perl, Python, Ruby, PHP (obv), and 
more, and I'm yet to see a compelling reason to want application variables. Let 
go of the possibility of application variables and your thinking will shift to 
other ways of solving the problem.

> I just wondered if there was a reason for not having this functionality or
> if it's on a road map somewhere or I've missed something :) ?

As far as I am aware, ASP and ASP.net are the only web technologies to support 
application variables out of the box. You think that's simply because the 
others just haven't gotten around to it yet?


Stuart Dallas
3ft9 Ltd
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to