Home >Backend Development >PHP Tutorial >A brief analysis of using Turck-mmcache compilation to accelerate and optimize PHP code_PHP tutorial
php_screw is indeed very good, but it can only play a role in encryption and has no acceleration or optimization effects.
Let’s take a look below:Turck MMCache
Its function is to accelerate and optimize php code by compiling php code. If the php code we publish is After compilation, it can also play some role in protecting the code.
Let’s compile compute.php and see the difference between the before and after code. The following is the source code of compute.php
//============ is used for loop calculations compute.php file ================// $a=0; $t=time(); for($i=0;$i<6000000;$i++) {$a=$a*$i;} $t1=time(); echo "
"; echo "It used:"; echo $t1-$t; echo "seconds"; ?>
The following is the compiled compute.php file
"; echo "It used:"; echo $t1-$t; echo "seconds"; ?>
2. Calculation Let’s take a look at the time it takes when it is not compiled, that is, calling the compute.php file I just wrote in the browser. You need to wait patiently for a while, about 30 seconds (under p3 500 CPU)
3. In order to compile php files conveniently, let's write a shell called encoder to compile php files.
<1> First copy the encoder.php file in 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 the 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 php encoder.php $src -o $src2; rm encoder.php mv $src $src.bak; mv $src.en $src;
<3> Give executable permissions 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. The source file is named compute.php.bak and saved
encode compute.php
<5> in the browser Call the compiled compute.php file and see if the speed improves?
In my case, it originally took 27 seconds, but after compilation it took 22 seconds
The difference between php_screw and turck-mmcache
php_screw is just a simple pair PHP code encryption has no acceleration and optimization effects.
Turck-mmcache compiles PHP code so that the speed of PHP code interpretation and execution can be close to the speed of binary code. It can speed up and optimize PHP code. However, the code compiled by turck-mmcache only turns the source code into binary code through certain rules, and there is no real encryption.
So if you want to ensure the absolute security of the code, use php_screw. If you consider factors such as speed, use turck-mmcache.