Author: Laruence () address of this article: www.laruence.com201208162701.html reprinted. Please indicate the source of the question about separating PHP compilation and execution. Someone has been raising this question and has been trying it. the author believes that after compilation and execution separation, the performance can be improved and code protection can be implemented. I am not very familiar with this feature.
Author: Laruence () address of this article: http://www.laruence.com/2012/08/16/2701.html reprint please indicate the source of PHP compilation and execution of separation this problem, has been raised, and has been someone try. the author believes that after compilation and execution separation, the performance can be improved and code protection can be implemented. I am not very familiar with this feature.
- Author: Laruence ()
- Address: http://www.laruence.com/2012/08/16/2701.html
- Reprinted please indicate the source
Some people have been asking about the issue of separating PHP compilation and execution. the author believes that after compilation and execution separation, the performance can be improved and code protection can be implemented.
I am not quite familiar with this feature, because there is an input-output ratio. let me explain it to you. However, in the end, I will provide you with a solution to implement this function.
1. PHP compilation is not very time-consuming
I have introduced in my previous articles that PHP compilation is a linear compilation process without optimization, so this process is very fast. the separation of compilation and execution puts forward the idea that after separation, the compilation process can be saved, which will greatly improve the performance.
Note: Some people have suggested that after compilation and execution are separated, various optimizations can be made during compilation, thus affecting the execution speed. This is indeed a research direction.
2. Development Speed
One of the advantages of PHP is that development, deployment, and debugging are very convenient and fast, and changes take effect immediately. This will make you feel more deeply when you fix online bugs in a 100,000 rush, if we adopt the compilation/execution separation, the changes need to be compiled first and then deployed before they can take effect. This is not a good thing for development.
3. We have third-party code caching tools such as APC/Zend O +.
Third-party code caching tools (Opcodes Cache) such as APC are relatively mature and transparent to developers. You only need to install APC on the server, the compilation/execution splitting performance can be improved.
4. Simple compilation/execution separation does not effectively implement Code Protection
The reason is very simple. PHP compilation is not optimized, so it is easy to be decompiled. Of course, I do not deny that using binary content does play a role.
In addition, there are some factors, such as the compilation/execution separation scheme which is being done by some people, but not yet mature.
Finally, we can do the same now. Here I will provide you with a similar solution.
First, I want to make an advertisement. In the future, the APC will be maintained by me. If you have any problems with the application of APC, contact me directly.
Regression: To separate compilation and execution, we can use APC to provide a family of apc_bin_dump and apc_bin_load functions that can export Opcodes caches to external files.
However, it is a pity that these functions have never been able to work properly before, and this is related to the previous developers who did not focus on this because of time.
After I reorganized the apc_bin series of functions, after the fix, this part of the function now finally works properly (starting from the APC-3.1.12), so based on these functions, we can implement separation of compilation and execution.
The idea is very simple. Locally export our PHP files to binfiles through apc_bin_dumpfile, and then read these binfiles through apc_bin_loadfile on the server. compile and execute separation. A simple sample code is as follows:
$ find ./ -name "*.php" -exec php -r "apc_bin_dumpfile(array('{}'), array(), '{}' . '.bin');" \;
Then the part of the file on the server is automatically loaded:
Of course, this is just a simple example. If you want to use it, you also need to consider the possibility that the cache will be swapped out. A solution is to set two auto-loading functions. The first one is as above, if the second file is called, it indicates that the cache is swapped out, and an empty file is included, so you can load the binfile again.
Of course, you can also package all the files into a binfile, load the file only once, and then hand it over to the APC Cache on the server. however, one thing to note here is,
For those who want the "Code Protection" function, you can use APC to complete these tasks for free. of course, because it is a memory image dump, it is affected by the size of the PHP version and the system, but for general applications, this can be easily matched.
Finally, thanks to @ cfc4n promoted this issue.
Comments
- , African black steamed bread writes: preemptible sofa
- , Writes: You are childish
- , Demon writes: if I say it together, will laruence be angry. Together! Together! Together!
- , Beimuaihui writes: Great, fast, and protected code.
- 2012/08/16, prairie writes: together! Together! Together! Together! Together! Together! Together! Together! Together!
- , Loki writes: Get these binfiles, and then apc_bin_loadfile, it will not be able to protect the code --
- Writes, Popeye: APC is promising, hahaha
- 2012/08/16, hileon writes: One of the advantages of PHP is that development, deployment, and debugging are very 'method' and 'convenience '.
- 2012/08/16, wclssdn writes: even if this method is not used, you can directly enable apc. Will opcode be cached if not? I have never been familiar with apc. I always think that it is enabled as long as the PHP file is not modified. the apc will skip the compilation process once and the next execution. directly execute the last compiled result .. is that true?
- , PHP rookie writes
- , Hellokitty writes: It seems that no for windows version is available for download. The latest version is 3.1.10.
- 2012/08/17, sesehai writes: Does APC currently support PHP-5.4.4?
- , Snow migratory birds writes: @ sesehai support
- 2012/08/20, crazymartian writes: Does Windows support windows?
- , MC writes: Excellent.
- , About PHP compilation and execution separation forest/coffee Chengdu professional php website production | forest/coffee Chengdu professional php website production writes: [...] Snow? PHP application Posted in: php/Tagged: separation of PHP compilation and execution [...]
- , Sevensoile writes: Hello, Senior. I have a question, but now I have a question about the background architecture of my website. Two options: 1. Php's existing framework (yii, zf, yaf) 2. The backend uses java and C language for logical processing and database operations. thrift is used for transferring php to focus on parallel processing and speed. I don't know how to balance this problem. I hope my predecessors can give me some advice on how to use php in Sina's meager background?
- 2012/08/25, on the PHP compilation and execution of separation | odd words wonderful thing-literature on small novels read xlinblog.sinaapp.com writes: [...] address: http://www.laruence.com/2012/08/16/2701.html [...]
- , Wee writes: after reading the previous article and this article, I suddenly thought of a slightly different question: php's support for the windows environment. Since the emergence of windows.php.net, php's support for windows has become almost no serious problem. The current contradiction is stuck in expansion. Php extension, except for those included in the release package of the windows version, other users want to find the extension for the windows environment. it is quite difficult to use dll files. PECL For Windows has been talking about it For N years and it has never been noticed. So far, we can only count on the files on the page http://downloads.php.net/pierre. The problem is that there are basically no extensions available for PHP5.4 ...... As a result, I had to bid my teeth and continue to use 5.4 for several new features. Why? The project depends heavily on several extensions, such as http, imagick, oauth ...... 5.4 of the new features are tempting, but it is not enough to offset the cost of solving these extensions. Someone must have said that the server must use a windows environment? The reason is similar to the previous article "language selection". The reason is "Easy to use ". Especially after considering the security factors. The windows server 2k8r2 environment can be easily handed over to developers for a little time. In the linux environment, you must carefully consider raising a full-time maintenance staff. Therefore, I don't quite understand why pecl is particularly inadequate in support of windows. Some extensions may make it difficult to provide support for windows, however, it is not difficult to provide the corresponding version 5.2 that has already been provided on 5.3 and 5.4? I once saw in a previous article that it was not difficult for laruence to compile windows extensions, but I still couldn't find a decent tutorial. Can laruence write a question? For PHP users who are not proficient in C, how can they compile the pecl extension for windows?
- , Smallyang writes
- , Anonymous writes: What is the performance of apc compared to eaccelerator? I have tested it before. The qps of the apc program is twice slower than that of ea.
- 2012/09/14, wonderful things-reading xlinblog.sinaapp.com in a literary qutan novel again, do not use (include/require) _ once writes: [...] separation of PHP compilation and execution [...]
- , Jianwu writes: Good! In the future, the underlying C code will be executed directly ~ However, the corresponding management tools should be added later. For example, php is automatically compiled into apc. bin every time it is modified.
- , Zhang Jian writes: worships predecessors
- , Using APC to protect PHP code | CNXCT team blog writes: [...] as early as 3-4 months ago, in the previous article about PHP compilation and execution separation, laruence blog mentioned APC as a solution for PHP code protection. It can be seen from the article that the idea of laruence is to export an opcode binfile to every PHP file. The binfile is also loaded one by one during loading, which also achieves code protection, however, if there are hundreds of PHP files in a project, there must be hundreds of binfiles, which are large in quantity, complicated in operations, inconvenient in management, and difficult to perform version Verification (which will be mentioned later ). In the end, we prefer to export a single binfile and load a single opcode binfile. In addition, loading a single binfile can prevent some files in the project from being inconsistent with the overall version. O & M colleagues no longer have to worry about the inconsistency between individual files and the entire project version. [...]
- , Using APC to protect PHP code | Security-script-O & m k. writes: [...] as early as 3-4 months ago, in the previous article about PHP compilation and execution separation, laruence blog mentioned APC as a solution for PHP code protection. It can be seen from the article that the idea of laruence is to export an opcode binfile to every PHP file. The binfile is also loaded one by one during loading, which also achieves code protection, however, if there are hundreds of PHP files in a project, there must be hundreds of binfiles, which are large in quantity, complicated in operations, inconvenient in management, and difficult to perform version Verification (which will be mentioned later ). In the end, we prefer to export a single binfile and load a single opcode binfile. In addition, loading a single binfile can prevent some files in the project from being inconsistent with the overall version. O & M colleagues no longer have to worry about the inconsistency between individual files and the entire project version. [...]
- 2012/12/06, dawsonJ writes: Will php implement pre-compiled commands like C # ifdef in the future?
- , On the PHP compilation and execution of separation | 5 iphp writes: [...] address: http://www.laruence.com/2012/08/16/2701.html [...]
- , Gaodi07 writes: I believe APC is getting better and better
- 2013/01/27, dailingang writes: I encountered a problem when using B ();?> Loading successful but reporting Class 'A' not found. Why?
- , Anonymous writes: I encountered a problem when using it. // t. phpclass a {public B () {return 'A' ;}}// dump. phpapc_bin_dumpfile (array (dirname (_ FILE __). '\ t. php '), array (), 't2. bin'); // test. php $ res = apc_bin_load (file_get_contents ('t2. bin'); var_dump ($ res); // exit; $ c = new a (); echo $ c-> B (); loading successful but reporting Class 'A' not found. Why?
- , Php writes: I was really taught that PHP was so powerful.
- , Yac (Yet Another Cache)-lockless shared memory Cache | afternoon nap writes: [...] about PHP compilation and execution separation [...]
- , Once again, do not use (include/require) _ once | afternoon nap writes: [...] about PHP compilation and execution separation [...]
- , PHP & "Data" URL scheme | afternoon nap writes: [...] about PHP compilation and execution separation [...]
- , On the PHP compilation and execution of separation | afternoon nap writes: [...] address: http://www.laruence.com/2012/08/16/2701.html [...]
- , Taint-0.3.0 (a xss codes sniffer) released | afternoon nap writes: [...] about PHP compilation and execution separation [...]
- , Accepting the things that happen to you in your life with grace and wisdom is a worthy goal. while we get into challenging situations often which test both grace and wisdom, the goal is to act and react gracefully as much as possible. it strengthens our c writes: Foarte bine, e un pas inainte.
- , Lein writes: ask how to use the bin_dump file of apc. The code found on the Internet is not detailed enough, and there is no example in the manual. My code: 1 dump file (/www/f1.php ):'. chr (10); function dosome () {echo date ('Y-m-d H: I: s');} 2. Run the dump file (/www/f2.php ):
- 2013/07/31, lein writes: @ why? Include ($ file); and $ file is an empty file. How can I ensure that apc will find this $ file from the cache instead of looking for this empty file?
- Writes, webmaster of www.tonitech.com,: I have recently considered this issue. Is it highly efficient to convert php into a compiled language? Considering the development efficiency, I can continue to play the interpreted language during the development process. In the formal environment, I changed to a compiled language. How can this happen?
- , Php_4, writes: hip-hop, isn't it?
Related posts:
- Php rfc: Make PHP foreach Support list
Copyright©2010 All Rights Reserved. this Feed is for personal use only. reposted or commercial applications that are not specified are prohibited. if the application is illegal, all legal consequences shall be borne by you. if you have any questions, you can send an email to my at laruence.com. (Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)