One more opcache for php (Preview) 30

Posted by moo Tue, 04 Apr 2006 02:36:00 GMT

I'm sure you use lighttpd because of performance and scalability, and many of you run php too. I'm please to introduce you another opcode cache for php.

Yes, another.

The preview version is deprecated. please check http://trac.lighttpd.net/xcache/wiki/GettingSource to get newer source.

and report problems at http://trac.lighttpd.net/xcache/newticket

Introducing

I myself, have used apc, mmcache/ea, ZendOptimizer, The only 3 choices before xcache. ab cache is too old and dead, saidly, before i use it. Every one of u write php script know them, and have one if them boost your php performance, because they're good.

But "What? Why you just introduce another opcode cacher?" It take some time to explain ... the short term: it give you one more choice. the long term: mmcache/ea is the most optimized php-opcache. ZendOptimizer isn't pre-built on all platform -- they release binary not source file. apc was stable on php4 but not works with php5, and now, is said works with php5 but php4 is left to desert...

Highlight spot of xcache

  1. cacher, similar as other opcaches.
  2. opcode disassembler, to see how your scripts looks after they're compiled into opcode.
  3. grows as php grows, using automated discover scheme by the devel, and the new changes to xcache to catch up new php version is brought to you easily.
  4. php4.x lastest is stably supported, php5.x lastest just works, php6-devel is supported for your further vision.
  5. many more ...

New function for script

$ grep proto *.c

mixed xcache_get(string name)
bool  xcache_set(string name, mixed value [, int ttl])
mixed xcache_isset(string name)
bool  xcache_unset(string name)
int   xcache_inc(string name [, int value [, int ttl]])
int   xcache_dec(string name [, int value [, int ttl]])

other proto need documented.

How to install

$ wget http://blog.lighttpd.net/files/xcache-preview.tar.gz
$ tar -zxf xcache-preview.tar.gz
$ cd xcache-preview
$ phpize
$ cat ./conf
$ ./configure --help
$ ./configure --enable-xcache-disassembler
$ make
$ su
# make install

take care about the output of make install append the following to php.ini:

[xcache]
xcache.size = 64M
xcache.mmap_path = "/tmp/xcache"
xcache.cacher = 1
zend_extension="/usr/.../extensions/..../xcache.so"
# or
extension="xcache.so"

Testing

restart your php (fastcgi or mod_php), check output for xcache status. if you see it there, you're done.

and finally test the opcode dumper:

$ ./phpdop.phpr ./phpdop.phpr
$ ./phpdc.phpr ./phpdc.phpr

Patch for hardened source (not tested)

Index: processor.m4
===================================================================
--- processor.m4    (revision 27)
+++ processor.m4    (working copy)
@@ -575,6 +575,9 @@

    /* reserved */
    DONE(reserved)
+ #if defined(HARDENING_PATCH) && HARDENING_PATCH
+   DISPATCH(zend_bool, created_by_eval)
+ #endif
    } while (0);
 ')
 dnl }}}

it is suggested to modify processor/processor.m4 directly as there might be spaces lost in blog.

Trackbacks

Use the following link to trackback from your own site:
http://blog.lighttpd.net/articles/trackback/170

Comments

Leave a response

  1. anonymouse Tue, 04 Apr 2006 05:27:01 GMT
    Hey, Sounds great, looks good. Why doesn't it have its own site? maybe go on sf.net?
  2. anonymouse Tue, 04 Apr 2006 05:28:16 GMT
    ohh, now imagine if it could optionally use memcache to centrally store various things rather than shm ;)
  3. bkw Tue, 04 Apr 2006 07:51:56 GMT
    Who wrote this? It certainly doesn't sound like Jan... The code contains references to http://xcache.sourceforge.net/, but Xcache on sf is a Java Object cache. That being said, I for one welcome our new opcache overlords! The demise of ea was troubling me a lot.
  4. refactored.net Tue, 04 Apr 2006 08:04:49 GMT
    Just wondering, has anyone got any benchmarks/performance stats on this package? I'm just about to release a php5.12 app for which I was going to purchase zend encoder to use with zend optimizer to increase speed. If this works just as well or better it could save me/my client a bundle!
  5. thomas Tue, 04 Apr 2006 08:51:17 GMT
    just for reference: zend optimizer is *not* an opcode cache! its merely a loader for their encrypted products which does some on-the-fly optimizations to the code. if you want zend's opcode cache you have to buy zend accelerator / zend platform.
  6. moo Tue, 04 Apr 2006 10:20:37 GMT
    me, moo, one of the lighttpd developers, wrote it, and have it online stable for a long time until i decide to release it. i'm going to setup a website for it, this is way the preview is here. the reference to http://xcache.sourceforge.net/ was wrong. although i've live with this name for a long time, i might change it if there's a better one.
  7. refactored.net Tue, 04 Apr 2006 13:20:56 GMT
    Another quick question - does this work with Zend Optimizer?
  8. foo Wed, 05 Apr 2006 01:42:36 GMT
    APC works fine with both PHP 4 and PHP 5.
  9. Mogrol Wed, 05 Apr 2006 08:03:41 GMT
    There doesn't seem to be any configure file in the archive, or am I missing something?
  10. User Wed, 05 Apr 2006 15:56:35 GMT
    When loading the extension (compiled exactly as in sample) got such PHP Warning: Unknown(): Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20020429/xcache.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20020429/xcache.so: undefined symbol: xc_coveragedump_dir in Unknown on line 0 When I compile the ext with --enable-xcache-coverage the module loads fine just segfaults on any code execution.. Any notes on this?
  11. moo Sat, 08 Apr 2006 01:21:27 GMT
    always run phpize to get configure file. undefined symbol: xc_coveragedump_dir ... thanks for your feedback :) one of the most important reasons to release (not only the preview version) and setup a site, is to attach more testers, make it more stable. there's too much left not released yet, such as a administration frontend, an coverage reader (read the dump and view in browser), an reallife testcase runner, and document! about all the functions (not just php function) in xcache (for user) and internal doc (for devel who's interested in the source code). i can't get apc start up(warm up) on fastcgi+php4+smp, strace -p `pid of php` gives me bunch of flock/fcntl-lock
  12. -HR Sun, 09 Apr 2006 08:21:28 GMT
    Mmh, if you can't get APC to start on your setup why not file a bug/try to fix it rather that spawning a whole new project? I think this bug has already been reported: http://pecl.php.net/bugs/bug.php?id=7141 A good opcode cache is a hell lot of work to maintain and since Yahoo uses APC I don't see it being left unmaintained so I see no compelling reason for creating a new one. Maybe your work would be more useful if you contributed to APC instead?
  13. moo Sun, 09 Apr 2006 11:47:31 GMT
    well, apc isn't the real reason i write another opcode cacher. i wrote it before i can't start it up. and i've used apc for a long time, already. and i've contribute many bug reports/patches to apc/ea too. and yes, apc WAS stable for php4. but some idea can't be done by simply writing patches. it might need a whole struct change, sometimes.
  14. refactored.net Mon, 10 Apr 2006 15:51:11 GMT
    Tried to install using instructions above, but with no luck. "cat ./conf" simply echo's to screen. Am I possibly missing a package?
  15. moo Tue, 11 Apr 2006 05:04:41 GMT
    ./conf is just a example, so cat to read it. the u have to do ./configure yourself with options you decided. according one of the above comments, coverage have to be enabled due to a bug.
  16. refactored.net Tue, 11 Apr 2006 07:29:27 GMT
    Sorry, I'm not very up-to-speed with linux. How would I create the ./configure file? I thought it was a script which ran through the process of switching on/off options for "make"?
  17. mOo Tue, 11 Apr 2006 11:08:50 GMT
    run phpize to build configure. it is only a preview package. thank u guys for your time trying it out.
  18. foo Tue, 11 Apr 2006 22:48:20 GMT
    $ phpize $ ./conf $ make (...snip...) ==== calc zend_op_array ================= expected: type function_name scope fn_flags prototype num_args required_num_args arg_info pass_rest_by_reference return_reference refcount opcodes last size vars last_var size_var T brk_cont_array last_brk_cont current_brk_cont try_catch_array last_try_catch static_variables start_op backpatch_count done_pass_two uses_this filename line_start line_end doc_comment doc_comment_len reserved created_by_eval missing : created_by_eval ==== store HashTable ================= ==== store zval ================= ==== store zend_op_array ================= ==== restore HashTable ================= ==== restore zval ================= ==== dprint HashTable ================= ==== dprint zval ================= ==== dprint zend_op_array ================= ==== dasm HashTable ================= ==== dasm zval ================= ==== dasm zend_op_array ================= ==== asm HashTable ================= ==== asm zval ================= ==== asm zend_op_array ================= make: *** [processor.out] Error 1

    System info: Slackware 10.0.0, GCC 3.3.4, PHP 5.1.2

  19. moo Wed, 12 Apr 2006 02:13:17 GMT
    created_by_eval is introduced by harded php patch. and congratulation! you're the first user (not devel) protected by xcache's struct detection :) it just stop instead of making a buggy xcache that is not for your version of php.
  20. ericj Fri, 14 Apr 2006 19:21:16 GMT
    there is no "configure" such file in the xcache-preview.tar.gz?
  21. ericj Fri, 14 Apr 2006 19:23:21 GMT
    sorry , I saw that ! I should use phpize ..
  22. ericj Fri, 14 Apr 2006 19:32:27 GMT
    After exec phpize it really made "configure" and then I exec ./configure --enable-xcache-disassembler and make Some error message like this happened. /root/src/xcache-preview/processor.c:1:28: processor_real.c: No such file or directory why? My OS is FreeBSD 6.1 RC#1
  23. mOo Sun, 16 Apr 2006 03:07:41 GMT
    autoconf, phpize, m4 is required. ctags is recomended but optional
  24. Rajib Roy Tue, 18 Apr 2006 14:55:05 GMT
    Great man. Working fullproof with php, Thanks for this
  25. Jedi Sat, 22 Apr 2006 13:22:16 GMT
    The m4/sed/awk scripts used to create the processor use non-standard GNU extensions. Even the Makefile requies GNU Make. It's why the package is tricky to build on BSD systems.
  26. wedge Mon, 24 Apr 2006 13:15:33 GMT
    yes, a bsd-compatible version would be very nice.
  27. moo Fri, 28 Apr 2006 05:54:44 GMT
    i simply don't have enough experience on those compatibility. once the site is up, any patch is welcomed.
  28. peterb Sat, 06 May 2006 19:57:36 GMT
    Cannot get to run with NuSphere dbg.so extension with apache2 and php-5.1.4. Error report says DBG extension must be loaded before any other. Does not seem to matter what order I place the extension commands in php.ini. Anybody any experience of this?
  29. null Sun, 14 May 2006 14:26:02 GMT
    fly# make /bin/sh /usr/xcache-preview/trunk/libtool --mode=compile gcc -I. -I/usr/xcache-preview/trunk -DPHP_ATOM_INC -I/usr/xcache-preview/trunk/include -I/usr/xcache-preview/trunk/main -I/usr/xcache-preview/trunk -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -DHAVE_CONFIG_H -g -O2 -c /usr/xcache-preview/trunk/xcache.c -o xcache.lo gcc -I. -I/usr/xcache-preview/trunk -DPHP_ATOM_INC -I/usr/xcache-preview/trunk/include -I/usr/xcache-preview/trunk/main -I/usr/xcache-preview/trunk -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -DHAVE_CONFIG_H -g -O2 -c /usr/xcache-preview/trunk/xcache.c -fPIC -DPIC -o .libs/xcache.o In file included from /usr/xcache-preview/trunk/xcache.c:9: /usr/include/malloc.h:3:2: #error " has been replaced by " In file included from /usr/xcache-preview/trunk/xcache.c:21: /usr/xcache-preview/trunk/align.h:16:1: warning: "ALIGN" redefined In file included from /usr/include/sys/param.h:109, from /usr/local/include/php/main/php.h:206, from /usr/xcache-preview/trunk/xcache.c:12: /usr/include/machine/param.h:79:1: warning: this is the location of the previous definition /usr/xcache-preview/trunk/xcache.c:24:23: processor.h: No such file or directory /usr/xcache-preview/trunk/xcache.c: In function `xc_entry_store_dmz': /usr/xcache-preview/trunk/xcache.c:149: warning: assignment makes pointer from integer without a cast *** Error code 1 Stop in /usr/xcache-preview/trunk.
  30. mOo Fri, 19 May 2006 03:30:04 GMT
    we have setup trac system at http://trac.lighttpd.net/xcache/, you may report bugs with http://trac.lighttpd.net/xcache/newticket include system version `uname -a`; php version `php -v` or check out phpinfo(), gcc version `gcc -v`
Comments