In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use Turck-mmcache compilation to accelerate and optimize PHP code. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Php_screw is really good, but it only plays the role of encryption, not acceleration and optimization.
Let's take a look at Turck MMCache.
Its function is to accelerate and optimize the php code by compiling the php code. If the php code we release is compiled, it can also play some role in protecting the code.
Let's compile compute.php to see the difference before and after the code. Here is the source code of compute.php.
Here is the compiled compute.php file
The copy code is as follows:
It is not difficult to find that by releasing the compiled program, it 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
two。 Enter 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, install
Make make install
4. Modify the php.ini file in the / etc/apache/ directory so that you can use turck-mmcache.
Add the following to the php.ini file:
The copy 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
Through the above 5 steps, turck-mmcache is ready to use, let's simply test the effect of acceleration and optimization.
test
1. Write a compute.php file to calculate a large number of cycles, take the system time before and after the operation, and finally subtract the two times to get the time used. (just a rough estimate)
The content of compute.php file is as follows
two。 Calculate the time it takes to compile, that is, to call the compute.php file I just wrote in the browser. You need to wait patiently for a while, about 30 seconds (under cpu of p3500)
3. To make it easy to compile the php file, let's write a shell called encoder to compile the php file.
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/
Create the encoder file with vi encoder, the contents are 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
Give executable permission to the shell you just wrote and move it to the / usr/bin directory
Chmod + x encoder mv encoder / usr/bin/
The compute.php file is compiled by encoder. The compiled compute.php is the compiled file, and the source file is named compute.php.bak to save.
Encode compute.php
Call the compiled compute.php file in the browser to see how fast it is.
Here, it takes 27 seconds to compile and 22 seconds to compile.
The difference between php_screw and turck-mmcache
Php_screw simply encrypts php code and has no acceleration or optimization effect.
Turck-mmcache compiles php code so that the speed of php code interpretation can be close to the speed of binary code. It can speed up and optimize the php code. But 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 your code, use php_screw, and if you take into account factors such as speed, use turck-mmcache.
This is the end of this article on "how to use Turck-mmcache compilation to accelerate and optimize PHP code". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.