A brief analysis of using Turck-mmcache compilation to accelerate and optimize PHP code _php tutorial

Source: Internet
Author: User
Php_screw is really good, but it can only play the role of encryption, and does not accelerate and optimize the role.
Let's take a look at the following: Turck MMCache
Its role is to speed up and optimize the PHP code by compiling the PHP code, if we publish the PHP code is compiled, but also some of the code to protect the role.
Below we compile the compute.php to look at the code differences before and after, the following is the source of compute.php
"; echo "It used:"; echo $t 1-$t; echo "seconds";?>
The following is the compiled compute.php file
Copy CodeThe code is as follows:


It is not difficult to find that by publishing a compiled program, you should be able to effectively prevent the program from being tampered with.
website
http://turck-mmcache.sourceforge.net/
How to get 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
Installation
1. Unzip the downloaded turck-mmcache-2.4.6.tar.gz under/usr/local
Tar zxvf turck-mmcache-2.4.6.tar.gz
2. Enter the turck-mmcache-2.4.6 directory, 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. Compiling, installing
Make make Install
4. Modify the php.ini file in the/etc/apache/directory in order to be able to use Turck-mmcache.
Add the following to the php.ini file:
Copy CodeThe code is as follows:
extension= "mmcache.so" mmcache.shm_size= "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
Through the above 5 steps, Turck-mmcache is already ready to use, and below we have a simple test for acceleration and optimization effects.
Test
1. Write a compute.php file to carry out a large number of cyclic calculations, take the system time before and after the operation, and finally subtract two times to get the time. (Just a rough estimate)
compute.php file contents are as follows
"; echo "It used:"; echo $t 1-$t; echo "seconds";?>
2. Calculate the time that was spent in the non-compile time, which is called in the browser I just wrote the compute.php file. Need to be patient for a while, about 30 seconds (P3 500 CPU)
3. To compile PHP files, let's write 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> Create encoder file with VI encoder as follows:
#!/bin/sh Clear src=$1; Echo $src; Src2= $src ". en"; echo $SRC 2; cp/usr/bin/encoder.php./encoder.php php encoder.php $src-o $src 2; RM encoder.php mv $src $src. bak; MV $src. En $src;
<3> Execute permissions on the shell you just wrote and move to the/usr/bin directory
chmod +x encoder MV encoder/usr/bin/
<4> compile compute.php files via encoder, compile compute.php as post-compile file, source file is named Compute.php.bak save
Encode compute.php
<5> call the compiled compute.php file in the browser to see if the speed is improved?
I'm going to use it for 27 seconds and compile it for 22 seconds.

The difference between Php_screw and Turck-mmcache
Php_screw is just a simple encryption of PHP code, and there is no acceleration and optimization effect.
Turck-mmcache is compiled by PHP code to allow the PHP code interpretation to be executed at a speed close to the binary code. Can play a role in accelerating and optimizing PHP code. But Turck-mmcache compiled code, only the source code through a certain rule into the binary code, and there is no real encryption.
So if you want to ensure the absolute security of the code to use Php_screw, if considering the speed and other factors, is to use Turck-mmcache

http://www.bkjia.com/PHPjc/327733.html www.bkjia.com true http://www.bkjia.com/PHPjc/327733.html techarticle Php_screw is really good, but it can only play the role of encryption, and does not accelerate and optimize the role. Let's take a look at: Turck mmcache its role is through the compilation of PHP code to ...

  • 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.