Analysis on using Turck-mmcache compilation to accelerate and optimize PHP code _ PHP Tutorial

Source: Internet
Author: User
Analyze how to use Turck-mmcache compilation to accelerate and optimize PHP code. Php_screw is really good, but it can only play the role of encryption, and does not play the role of acceleration and optimization. Next let's take a look: TurckMMCache is really good through the compilation of php code, but it can only play the role of encryption, and does not play the role of acceleration and optimization.
Let's take a look: Turck MMCache
It accelerates and optimizes php code by compiling php code. if the released php code is compiled, it can also protect the code.
Next we will compile compute. php to see the difference between the code before and after, the following is the source code of compute. php
"; Echo" It used: "; echo $ t1-$ t; echo" seconds ";?>
The following is the compiled compute. php file.

The code is as follows:




It is not difficult to find that the compiled program should be released to effectively prevent program tampering.
Website
Http://turck-mmcache.sourceforge.net/
How to obtain turck-mmcache
1 can be obtained through its website
2 download from the following URL
Http://prdownloads.sourceforge.net/turck-mmcache/turck-mmcache-2.4.6.tar.gz? Download
Install
1. put the downloaded turck-mmcache-2.4.6.tar.gz to/usr/local for decompression.
Tar zxvf turck-mmcache-2.4.6.tar.gz
2. go to the turck-mmcache-2.4.6 directory and configure
Cd turck-mmcache-2.4.6 export PHP_PREFIX = "/usr" $ PHP_PREFIX/bin/phpize./configure -- enable-mmcache = shared -- with-php-config = $ PHP_PREFIX/bin/php-config
3. Compile and install
Make install
4. modify the php. ini file in the/etc/apache/directory to use turck-mmcache.
Add the following content to the php. ini file:

The code is as follows:


Extension = "mmcache. so "mmcache. shm_size = "16" mmcache. cache_dir = "/tmp/mmcache" mmcache. enable = "1" mmcache. optimizer = "1" mmcache. check_mtime = "1" mmcache. debug = "0" mmcache. filter = "" mmcache. shm_max = "0" mmcache. shm_ttl = "0" mmcache. shm_prune_period = "0" mmcache. shm_only = "0" mmcache. compress = "1"


5. restart Apache
/Etc/rc. d/rc. httpd restart
In the preceding five steps, turck-mmcache can be used. below we will perform a simple test on the acceleration and optimization results.
Test
1. compile a compute. php file to perform a large number of cyclic calculations. obtain the system time before and after the calculation, and then subtract the two times to get the time used. (Just a rough estimate)
The content of the compute. php file is as follows:
"; Echo" It used: "; echo $ t1-$ t; echo" seconds ";?>
2. calculate the time used when the file is not compiled, that is, call the compute. php file I just wrote in the browser.Wait patiently for about 30 seconds (under p3 500 cpu)
3. for the convenience of compiling PHP files, we compile a shell called encoder to compile php files.
<1> first copy the encoder. php file under the/usr/local/turck-mmcache-2.4.6 directory to the/usr/bin directory
Cp/usr/local/turck-mmcache-2.4.6/encoder. php/usr/bin/
<2> use vi encoder to create an encoder file. the content is as follows:
#! /Bin/sh clear src = $1; echo $ src; src2 = $ src ". en "; echo $ src2; cp/usr/bin/encoder. php. /encoder. php encoder. php $ src-o $ src2; rm encoder. php mv $ src. bak; mv $ src. en $ src;
<3> grant the executable permission to the shell you just wrote and move it to the/usr/bin directory.
Chmod + x encoder mv encoder/usr/bin/
<4> compile the compute. php file through encoder. after compilation, compute. php is the compiled file, and the source file is named compute. php. bak for saving.
Encode compute. php
<5> in the browser, call the compiled compute. php file to see if the speed is improved?
Here, it takes 27 seconds and 22 seconds after compilation.

Differences between php_screw and turck-mmcache
Php_screw only encrypts php code and has no acceleration or optimization effect.
Turck-mmcache compiles php code so that php code can be interpreted and executed at a speed close to that of binary code. It can accelerate and optimize php code. However, the compiled code of turck-mmcache only turns the source code into binary code through certain rules without real encryption.
So if you want to ensure the absolute security of the code, use php_screw. if you consider the speed and other factors, use turck-mmcache.

Bytes. Let's take a look: Turck MMCache is used to compile php code...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.