PHP caching with eAccelerator

Discussion in 'Servers and Control Panels' started by PerfectSQL, Mar 19, 2005.

  1. PerfectSQL

    PerfectSQL Server Admin

    364
    115
    +1
    There are a number of PHP caching programs available, most offer lack-luster performance or are prohibitively expensive like Zend Accelelerator. MMCache was one of the best for a long time(or the best in my opinion), but the author could not continue development due to other commitments, and as of PHP 4.3.10 is broken: Enter eAccelerator. eAccelerator is a development branch of MMCache with continued development and will support all current and future versions of PHP. The principal upon which PHP caching works is simple, it increases performance of PHP scripts by caching them in compiled state, so that the overhead of compiling is almost completely eliminated.

    PHP eAccelerator can be found at the following URL

    http://eaccelerator.sourceforge.net/
    or
    http://sourceforge.net/projects/eaccelerator/

    Installation if fairly straight forward..

    Download the file to your server from http://prdownloads.sourceforge.net/eaccelerator/eaccelerator-0.9.2a.tar.gz?download

    i.e ...
    # wget http://switch.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.2a.tar.gz

    extract the archive
    # tar zxvf eaccelerator-0.9.2a.tar.gz

    change to the source dir
    # cd eaccelerator

    export the following system var
    # export PHP_PREFIX="/usr/local"
    (this is the corect location on cpanel servers, some servers it may be in "/usr")

    then phpize...
    # $PHP_PREFIX/bin/phpize

    configure the program...
    # ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config

    compile the program..
    # make

    install the program...
    # make install

    create a temp directory for cached scripts and set the perms..
    # mkdir /tmp/eaccelerator
    # chmod 0777 /tmp/eaccelerator

    edit your php.ini file
    # pico -w /usr/local/lib/php.ini
    may be located in "/usr/lib/php.ini" on some machines

    add the following to the end of your php.ini to install it as a Zend extension

    Code:
    zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20020429/eaccelerator.so"
    eaccelerator.shm_size="16"
    eaccelerator.cache_dir="/tmp/eaccelerator"
    eaccelerator.enable="1" 
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.debug="0"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="0"
    eaccelerator.shm_prune_period="0"
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="9"
    
    or as a php extension

    Code:
    extension="/usr/local/lib/php/extensions/no-debug-non-zts-20020429/eaccelerator.so"
    eaccelerator.shm_size="16"
    eaccelerator.cache_dir="/tmp/eaccelerator"
    eaccelerator.enable="1" 
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.debug="0"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="0"
    eaccelerator.shm_prune_period="0"
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="9"
    
    make sure the path to the extension matches the directory it was installed to on your system after running make install.

    Restart apache, then make sure it works by viewing your php info it should say...

    and there will be a section related to eAccelerator

    The only setting you ussually need to change is the eaccelerator.shm_size, 16 is standard and fine in most cases, 32 on a large macine, or in the case of TAZ which runs a dedicated web machine we use 64 MB.

    We have seen speed increases of up to 400% on some scripts, with a norm being 150 - 200% once the script is cached.

    We hope you have found this TAZ tutorial helpfull.
     
    1
  2. Brook

    Brook Devotee

    2,329
    630
    +19
    WOW thank you for sharing your trade secrets with us!

    Very kind of you!
     
  3. Brook

    Brook Devotee

    2,329
    630
    +19
    PS I've only just got a dedicated server so am too scared to try it just yet! (have saved it for future reference tho).. Give me a couple of months and I'll give it a go! :)
     
  4. Pluc

    Pluc Neophyte

    4
    1
    +0
    Hi !

    First, i would like to give you a thumbs up for this nice tutorial :tup: :worship:

    But i have a little problem....
    In my php info, normally it must show :
    But i have :

    The end of my php.ini :
    I have try to install it as a Zend extension, but Apache wont restart.
    Now, thats very fast :worship: , but i juste want to know if this is normal to have like 2 zend optimiser running ?
    I'm a little bit confused about the informations i see in php info !

    Thanks :tiphat:

    I'm from Quebec, sorry for my english :irked:
     
  5. PerfectSQL

    PerfectSQL Server Admin

    364
    115
    +1
    change
    to

    running both may cause more harm than good.
     
  6. KW802

    KW802 Oooh, something shiny!

    2,826
    887
    +536
    PerfectSQL,

    Nice instructions, thank you. I was wondering though if you'd mind going into for a bit on when a person's server is a good candidate for something like this? Is this one of those optimizations that can't hurt even if it's not needed yet or should should installation be held off until really needed?

    Thanks,
    Kevin
     
  7. Brook

    Brook Devotee

    2,329
    630
    +19
    I would be grateful if you could suggest any changes required for a not-so-hi-tec server. For eg, a Pentium 3 1Ghz with 256MB RAM (I may expand the ram soon).

    Thanks.
     
  8. Pluc

    Pluc Neophyte

    4
    1
    +0
    Thanks
    ;)
     
  9. PerfectSQL

    PerfectSQL Server Admin

    364
    115
    +1
    Firstly, I would not run any bigger cache size than 16. Secondly, if you run MySQL on this server I'd review the thread I posted on MySQL tweaking. Mke sure your buffers are not too big, becuase if they are it may cause your memory to swap. I ran a vbulletin with 200 concurrent users a few years back on a Poweredge 800 Mhz p3, with 512 ram .. it actually ran fine most of the time. If your on a budget and wanted to upgrade i'd recomend a bit more am if anything.
     
  10. Brook

    Brook Devotee

    2,329
    630
    +19
    Thanks!

    And again, there's no wonder you guys have a great reputation, ever so helpful - and we're not even your customers! (yet!)
     
  11. Brook

    Brook Devotee

    2,329
    630
    +19
    P.s. would buffer sizes would you recommend? (should I ask this on that thread instead? - or you can quote and reply over there if you like as I'll keep a check on it.. :))
     
  12. PerfectSQL

    PerfectSQL Server Admin

    364
    115
    +1
    Depends on how many connections you actually have going on. How many sites and online users do you ussually have?
     
  13. Brook

    Brook Devotee

    2,329
    630
    +19
    The server is host to few static html sites (which use very little bandwidth) and my forum which has around 40 to 50 users online at peak times, but I think this will grow.

    Here is my current my.cnf file...

    Code:
    [mysqld]
    skip-innodb
    max_connections = 500
    key_buffer = 16M
    myisam_sort_buffer_size = 64M
    join_buffer_size = 1M
    read_buffer_size = 1M
    sort_buffer_size = 2M
    table_cache = 1024
    thread_cache_size = 64
    wait_timeout = 7200
    connect_timeout = 10
    tmp_table_size = 32M
    max_allowed_packet = 16M
    max_connect_errors = 10
    query_cache_limit = 1M
    query_cache_size = 16M
    query_cache_type = 1
    
    [mysqld_safe] 
    open_files_limit = 8192
    
    [mysqldump]
    quick
    max_allowed_packet = 16M
    
    [myisamchk] 
    key_buffer = 64M 
    sort_buffer = 64M
    read_buffer = 16M
    write_buffer = 16M
    
    If you need any further info please let me know. And thanks for your help :)
     
  14. Tomek

    Tomek Neophyte

    8
    1
    +0
    I would lower the compression level from the default:
    Code:
    eaccelerator.compress_level="9"
    to:
    Code:
    eaccelerator.compress_level="1"
    The value of 9 is the highest compression level. In my opinion it is too high.
     
  15. KW802

    KW802 Oooh, something shiny!

    2,826
    887
    +536
    PerfectSQL, any thoughts?
     
  16. PerfectSQL

    PerfectSQL Server Admin

    364
    115
    +1
    Any server that does PHP scripts is a good candidate for this.. I have never seen any ill effects from using a caching application. Actually the only time I have seen any negative is when a new release of php breaks compatability, but I only saw that once with mmcache.
     
  17. Brook

    Brook Devotee

    2,329
    630
    +19
    Do you need any more info from me PerfectSQL?
    (I posted above, not sure if you missed it :-( )

    P.s. shall I post the info in the 'MySQL Server Tweaking Basics' thread instead as it probably belongs there and not this one?
     
  18. PerfectSQL

    PerfectSQL Server Admin

    364
    115
    +1
    that config is fine as long as you are not lagging at peak usage times. If you are lagging change the read, sort and join buffer sizes to 768k.

    Oh I just noticed your sort buffer is 2 megs, drop that to 1.

    Also, run the "free" command at the shell prompt during peak time and paste the results here, so we can see how much of your ram is being consumed.
     
  19. Brook

    Brook Devotee

    2,329
    630
    +19
    Hi PerfectSQl, thanks for getting back to me.

    I've brought the sort buffer down to 1 as suggested and have reboot the server. I've also taken a quick 'free' command whilst there were only 24 users online (I'll post another one when we get about 40 or so online...):


    Mem: 252944 226384 26560 0 11792 77140
    -/+ buffers/cache: 137452 115492
    Swap: 522104 0 522104


    Here's with 31

    Mem: 252944 241980 10964 0 13920 90236
    -/+ buffers/cache: 137824 115120
    Swap: 522104 936 521168
     
  20. KW802

    KW802 Oooh, something shiny!

    2,826
    887
    +536
    In that case it sounds like something I may need/want to play with. Thanks. :cool:

    One more question if you don't mind.... In another thread The Sandman has mentioned how many scripts were being cached; where would that be viewable?

    Thanks,
    Kevin
     
Verification:
Draft saved Draft deleted