John Smith
John Smith

Reputation: 6197

php cache class?

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

Answers (3)

Ken Le
Ken Le

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

Pekka
Pekka

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.

Upvotes: 2

ajreal
ajreal

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

Related Questions