1

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" ?

1
  • 1
    How much time is "time"? Milliseconds? Seconds? Commented Dec 5, 2011 at 12:59

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.