Reputation: 6197
My big problem is I need to create some objects, and I found that just to include() their class itself needs time. I tried to use serialize(), unserialize() to speed up object creations, but it only helped some milliseconds, the classes themselves still needs to be required. But this require itself causes delay. Is there a way to cache "classes" ?
Upvotes: 1
Views: 6343
Reputation: 1805
If you don't want to write your class. Try phpFastCache.com, it's good and simple for beginner.
Okay, If you want to write a class, and cache your code, you can use APC, MemCached, WinCache. Here is the class for it. However, optcode caching only reduce database call or save API transactions for your website. IT IS NOT GONNA SPEED UP THE WAY YOU CODE. It's only speed up your page load by saving your time on connect and get information from database or API / Functions.
You have to try PHPaccelerators or Varnish. These are cache php code, and your server won't complite it again until it is needed.
If you don't want any of them, create a RAM DISK, and just serialize(), unserialize() into files of the RAM DISK. RAM is always faster than DISK.
Upvotes: 1
Reputation: 449475
There are ways to speed this up like bytecode caching, but it's often not an option on shared hosting, creates a new dependency and should not be necessary at all for a small project - smartening up the code will probably fix the problem.
Look exactly at what is being included, and whether all of it is needed all the time.
Here is some advice on how to split code into more manageable chunks: How can I improve the performance of 'include()s' in PHP?
Look into PHP autoloading: http://php.net/manual/en/language.oop5.autoload.ph
Upvotes: 2
Reputation: 47321
Yes, is called APC (Alternative PHP Cache) :- http://php.net/manual/en/book.apc.php
Is a native PHP modules, compiled into PHP compiler
Second thought, classes / object is cacheable,
but not those resources like XML object, database result object
Upvotes: 2