oop - Is there a central / main context in PHP? -


here question: consider django or web2py in python (as web frameworks) or java web applications (being simple servlets apps or complex struts2/wicket/whatever frameworks). share @ least 2 things like:

  1. there's context environment or way access data out of request or session contexts (i.e. global data, singletones, pools ... can share in-memory values , behavior).
  2. classes loaded/initialized once. perhaps i'm missing afaik in php class loaded , initialized in per request basis (so, in regular class, if (e.g.) modify static value, live in current request, , simultaneous request hitting value different one).

is there way in php? e.g. in python/django can declare regular class , class can hold static data or true singleton (again: perhaps pool or kind of central queue manager), , same object until django server dies (note: modules in python kept loaded in python context when imported).

the fact php's "context" lives on per-request basis pretty core how language works web servers.

if want working more java or other languages data doesn't reset every request, have 2 options:

  • serialize data file, db, whatever, , reload on next request
  • instead of serving pages through web server, write server using php

serializing data storage , reloading on subsequent requests typical approach.

writing server in php itself, while possible, not recommend. despite effort, php still has sort of bad memory management, , encounter memory leaks in long-running php processes.


Comments