Skip to main content

What is a bytecode cache and how can I use one in PHP?


I searched on the Web and came to know that PHP code can be compiled to have performance boost. But how to do it? Can I compile both procedural and object oriented PHP code?



Source: Tips4allCCNA FINAL EXAM

Comments

  1. The basic idea, when executing a PHP script is in two steps :


    First: the PHP code, written in plain-text, is compiled to opcodes
    Then: those opcodes are executed.



    When you have one PHP script, as long as it is not modified, the opcodes will always be the same ; so, doing the compilation phase each time that script is to be executed is kind of a waste of CPU-time.

    To prevent that redundant-compilation, there are some opcode caching mechanism that you can use.

    Once the PHP script has been compiled to opcodes, those will be kept in RAM -- and directly used from memory the next time the script is to be executed ; preventing the compilation from being done again and again.


    The opcode cache which is used the most is APC - Alternative PHP Cache :


    See on PECL to download the APC extension
    And here's its manual


    Once APC has been installed and configured properly, there is nothing you have to modify in your PHP code : APC will cache the opcodes, and that is all -- the process is totally invisible for your application.

    ReplyDelete
  2. But how to do it?


    Easy.
    First of all you have to do some profiling to be sure that code parsing being a bottleneck of your site, and all other obvious ones like unoptimized data storage, slow algorithms, data mining and network calls were optimized.

    Easiest way to determine if you need opcode cache or not would be just putting this line at the very top of your most used page

    $timer_start = microtime(1);


    and this line at the very end:

    echo "Generated in ".(round((microtime(1) - $timer_start),4))." sec.";


    if time is more than 0.01, you have other things to optimize first, because you will notice no effect from opcode cache.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 1 Final Exam 2011 latest (hot hot hot)

  Hi! I have been posted content of ccna1 final exam (latest and only question.) I will post the answer and insert image on sunday. If you care, please subscribe your email an become a first person have full test content. Subcribe now  Some question  have not content because this question have images content. So that can you wait for me? SUNDAY 1. A user sees the command prompt: Router(config-if)# . What task can be performed at this mode? Reload the device. Perform basic tests. Configure individual interfaces. Configure individual terminal lines. 2. Refer to the exhibit. Host A attempts to establish a TCP/IP session with host C. During this attempt, a frame was captured with the source MAC address 0050.7320.D632 and the destination MAC address 0030.8517.44C4. The packet inside the captured frame has an IP source address 192.168.7.5, and the destination IP address is 192.168.219.24. At which point in the network was this packet captured? leaving host A leaving ATL leaving...