Preloading PHP Objects to optimize on performance
Moderator: General Moderators
-
sunilbhatia79
- Forum Newbie
- Posts: 24
- Joined: Sun Nov 11, 2007 9:37 pm
- Location: Mumbai, India
Preloading PHP Objects to optimize on performance
Hi All,
Has anyone done any research on how could PHP objects could be preloaded so that execution optimization could be achieved.
For example, I could have a Constants class that would define all the constants that I need in the project. I would just want to load that once so that other classes could use them as and when required.
The problem that I face is that everytime I have to include the file - which makes in compile and execute - which means that after the script finishes its execution - the memory is cleared.
Its the same case with Static classes.
I am sure that there could be a framework or a work around to have these objects preloaded to achieve execution optimization.
Can someone please help?
Regards,
Suniil
http://www.sunilb.com - PHP5 Tutorials
Has anyone done any research on how could PHP objects could be preloaded so that execution optimization could be achieved.
For example, I could have a Constants class that would define all the constants that I need in the project. I would just want to load that once so that other classes could use them as and when required.
The problem that I face is that everytime I have to include the file - which makes in compile and execute - which means that after the script finishes its execution - the memory is cleared.
Its the same case with Static classes.
I am sure that there could be a framework or a work around to have these objects preloaded to achieve execution optimization.
Can someone please help?
Regards,
Suniil
http://www.sunilb.com - PHP5 Tutorials
- sergio-pro
- Forum Commoner
- Posts: 88
- Joined: Sat Dec 27, 2008 12:26 pm
Re: Preloading PHP Objects to optimize on performance
Hi
There is a Shared Memory module that allows you to work with memory http://www.phpdig.net/ref/rn57.html
Im not sure if it really will increase performance, if you store some data in memory this way.
If php pasring/compiling is too slow for your task - then:
Dont use PHP, use Java
There is a Shared Memory module that allows you to work with memory http://www.phpdig.net/ref/rn57.html
Im not sure if it really will increase performance, if you store some data in memory this way.
If php pasring/compiling is too slow for your task - then:
Dont use PHP, use Java
Re: Preloading PHP Objects to optimize on performance
Yep, aggressive loading ( "preloading" ) vs lazy loading ("auto loading"), you could also employ lazy loading and then sprinkle aggressive loading over your cake, before you ever so elegantly "eat it", too.
-
sunilbhatia79
- Forum Newbie
- Posts: 24
- Joined: Sun Nov 11, 2007 9:37 pm
- Location: Mumbai, India
Re: Preloading PHP Objects to optimize on performance
Thanks guys.
I have been through the Share Memory Module on phpdig. Need to study more.
My question however is that even if I create data in Shared Memory - wont it get destroyed once my PHP script completes its execution?
I am looking at a functionality that Java Containers provide - where the static classes are loaded in memory and always remain there till the time the container is not stopped.
A little bit more guidance will help me a lot!
Regards,
Suniil
I have been through the Share Memory Module on phpdig. Need to study more.
My question however is that even if I create data in Shared Memory - wont it get destroyed once my PHP script completes its execution?
I am looking at a functionality that Java Containers provide - where the static classes are loaded in memory and always remain there till the time the container is not stopped.
A little bit more guidance will help me a lot!
Regards,
Suniil
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Re: Preloading PHP Objects to optimize on performance
Really, the best you can do with PHP is caching the opcodes from files using APC. The great thing about PHP is that you lose all state between results! It means you don't get any odd effects from old requests wreaking havoc on your newest request.
You can try the PHP module for Apache, which keeps the PHP interpreter around between requests. It won't preserve class definitions, but it saves the background machinery.
You can try the PHP module for Apache, which keeps the PHP interpreter around between requests. It won't preserve class definitions, but it saves the background machinery.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Preloading PHP Objects to optimize on performance
That is exactly how PHP and Apache are supposed to work. I should ask the obvious question: Do you actually have a performance problem? If not then you should not be searching for anti-PHP techniques in PHP.sunilbhatia79 wrote:The problem that I face is that everytime I have to include the file - which makes in compile and execute - which means that after the script finishes its execution - the memory is cleared.
Its the same case with Static classes.
(#10850)
-
sunilbhatia79
- Forum Newbie
- Posts: 24
- Joined: Sun Nov 11, 2007 9:37 pm
- Location: Mumbai, India
Re: Preloading PHP Objects to optimize on performance
I don't have a performance issue as of now. But was wondering how I could help improve performance while building an Enterprise level application. I love PHP and that's the reason why I am investing efforts on understanding how this could be handled.arborint wrote:That is exactly how PHP and Apache are supposed to work. I should ask the obvious question: Do you actually have a performance problem? If not then you should not be searching for anti-PHP techniques in PHP.sunilbhatia79 wrote:The problem that I face is that everytime I have to include the file - which makes in compile and execute - which means that after the script finishes its execution - the memory is cleared.
Its the same case with Static classes.
The project my friend and I are trying to build contain a list of Keywords - which we need preloaded in memory always (after reading them from DB). This means that whenever the script runs - we should have a handle to the list of keywords object - so that I would not have to read DB and load the list for each request.
Regards,
Suniil
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Preloading PHP Objects to optimize on performance
Since you don't have a problem now, you are wasting your time investigating because you don't know what the performance problems might be.sunilbhatia79 wrote:I don't have a performance issue as of now. But was wondering how I could help improve performance while building an Enterprise level application. I love PHP and that's the reason why I am investing efforts on understanding how this could be handled.
How big is the list? I would wrap the Keywords list in an object and put them somewhere easy for not -- like in the DB. Then when this menacing performance problems arrives you can use a faster subsystem to store the list. You should be focused now on getting the design right.sunilbhatia79 wrote:The project my friend and I are trying to build contain a list of Keywords - which we need preloaded in memory always (after reading them from DB). This means that whenever the script runs - we should have a handle to the list of keywords object - so that I would not have to read DB and load the list for each request.
(#10850)
-
sunilbhatia79
- Forum Newbie
- Posts: 24
- Joined: Sun Nov 11, 2007 9:37 pm
- Location: Mumbai, India
Re: Preloading PHP Objects to optimize on performance
Ok. For now will focus on the design.
One last question
What type of faster sub-system would you use if you face issues with performance. Asking this now so that I could do a bit of research in free time.
Thanks
Suniil
One last question
What type of faster sub-system would you use if you face issues with performance. Asking this now so that I could do a bit of research in free time.
Thanks
Suniil
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Preloading PHP Objects to optimize on performance
A faster database server would be first because that's really easy, then probably Memcache.
(#10850)