0

I think this cannot be done do to the fact the PHP is a stateless language. But I will ask anyway...

I've created a home-grown MVC framework. The classes are all namespaced. On initial load I instantiate my custom Autoload class. A method of this class scans registered class directories (stored in the application config) and creates an array of fully qualified class names to paths. The array is stored as a protected member of this class. This member array is used by the spl_autoload() implementation. The Autoloader object is cached and reused on each http request.

This is fine and well. However, it irks me that every time an http request comes in to the domain my bootstrap routine has to register the autoload method to the __autoload stack. I would love to register it once and leave it alone.

tereško
  • 58,060
  • 25
  • 98
  • 150
Neil Girardi
  • 4,533
  • 1
  • 28
  • 45
  • No. You will have to attach autoloader the autoloader every time you initialize your application. But you could stop scanning the directories as building classmap on very call. Just do it once and dump the result in either php file as array or cache it in APC. – tereško Dec 01 '13 at 06:09
  • @tereško Thanks for the reply. Yes, the scanning of the directories only happens once. – Neil Girardi Dec 01 '13 at 06:43

1 Answers1

0

I think the closest you can get to this would be opcode caching, where the parsing is done and machine language is built. Beyond that, you're right in that being a stateless language means it has to be built every time. I've never delved into it myself (so I'm not sure it would answer your question), but there is also pre-compiled PHP.

Community
  • 1
  • 1
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • Thanks for the reply. When you say pre-compiled PHP are you referring to something like Facebook's HipHop runtime? – Neil Girardi Dec 01 '13 at 03:12
  • Yes. I've never fooled with it myself but that's the only other way I could see this working. Otherwise PHP is at least having to rebuild the program stack every time. – Machavity Dec 01 '13 at 03:14