I wrote struts a few years ago, and later I began to use php and liked php's simplicity. As project participants grow, there must be specifications and procedures. So I started to study some frameworks and encapsulated simple router and mvc components. Recently, when I was reading another php framework, I wrote struts a few years ago. Later I started using php and liked php's simplicity.
As project participants grow, there must be specifications and procedures. So I started to study some frameworks and encapsulated simple router and mvc components.
Recently, when I was looking at another php framework, I suddenly felt a little confused.
In applications such as java, the encapsulated framework can be permanently stored in the memory without loading each time. However, the php mechanism is to load a request at a time. Therefore, every request must process the configuration file and load a bunch of encapsulated items.
Does php also store some things in the memory? Please give explanations for this part.
Reply content:
I wrote struts a few years ago, and later I began to use php and liked php's simplicity.
As project participants grow, there must be specifications and procedures. So I started to study some frameworks and encapsulated simple router and mvc components.
Recently, when I was looking at another php framework, I suddenly felt a little confused.
In applications such as java, the encapsulated framework can be permanently stored in the memory without loading each time. However, the php mechanism is to load a request at a time. Therefore, every request must process the configuration file and load a bunch of encapsulated items.
Does php also store some things in the memory? Please give explanations for this part.
First of all, I have to say that php is really "very weak" in this regard. "Very weak" does not mean that php really hates "bad". It is undeniable that php is the best dynamic template language.
Php is a dynamic interpreted language and provides very limited functions in terms of language. This is probably why php is very easy to use. So we found out many excellent frameworks (Yii, Zend Framework ...), A collection of awesome technologies (Cache/queue/cluster/replica set/asynchronous/Configuration System/log system/Monitoring System/Automation ...) at this level, you may have some questions (some questions about the php framework). First of all, congratulations. You have reached the intermediate level of php development at least, and many people dare not try it. This kind of doubt is a normal response. Because of your understanding, you will think about the entire process. If every request is processed like this, php is at the code level (PHP5 is collectively referred to as OP +) the accelerator/cache is provided. It is said that the performance can be improved by more than 30%, and pass can be used. In fact, laruence reflected on this issue a few years ago and developed Yaf (the framework already exists in the memory when php is started). I will not talk about Yaf here, if you are interested, you can check it out.
Apc, zend optimizer plus, and opcache from php 5.5.
All files are pre-compiled and opcode is cached in the memory. This is a common solution to your confusion. We recommend that you use it as appropriate to increase php speed by 20 to 300.
But for both php and java, the bottleneck is actually on the database io. After saving the file loading and configuration steps, the speed is generally not increased by 20 to 100 age points, in particular, database operations are frequent.
The main focus of this talk is on your questions, and you will not be involved in other irrelevant things.
PHP itself will not resident in the cache. When a request ends, PHP will stop executing it. This is the characteristic of PHP, and there is no need to consider memory, concurrency, and so on.
But what you said
"So every request must process and load the configuration file, and loading a bunch of packages is not a waste ."
Not completely accurate. Mainstream PHP frameworks are cache-based, and the cache mechanism avoids this problem.
PS: no one answered the question. It is estimated that it was written by the landlord."Please give an explanation for this piece ."Scared away. I am not a big bull, a common PHP programmer. I hereby declare that.
Php has an opcode cache mechanism similar to java bytecode. php files running on the server are cached in the memory in the form of compiled opcode.
Common opcode cache reference Wikipedia: PHP accelerator list
After 5.5, PHP officially built Zend Optimizer.
By the way, we recommend that configuration files and templates exist in php format to maximize the use of opcode cache and reduce disk IO.
Some fixed configuration items can be written into apache environment variables, which can be read using $ _ ENV in php. Each time apache fork generates a process, these configurations are carried and resident memory is used.
Opcode is a way of thinking, and accelerate and so on. I just heard from Daniel. Http://www.infoq.com/cn/presentations/php-project-control