Website architecture-Some doubts about PHP framework

Source: Internet
Author: User
I wrote the struts all the way a few years ago, and then started using PHP, like the simplicity of PHP.

With the growth of the project participants, there must be a norm, to have the process, so began to study a number of frameworks, they also encapsulated a simple ROUTER,MVC part.

When I recently looked at another PHP frame, I suddenly felt a little puzzled.

In a Java-like application, the framework part of our package can be persisted in memory without having to load it every time. But PHP's mechanism is to request a single load at a time. So every request, to handle loading a configuration file, loading a bunch of packaged things is not a bit too wasteful.

Is that PHP also putting something in memory? For this piece please Daniel explain to explain.

Reply content:

I wrote the struts all the way a few years ago, and then started using PHP, like the simplicity of PHP.

With the growth of the project participants, there must be a norm, to have the process, so began to study a number of frameworks, they also encapsulated a simple ROUTER,MVC part.

When I recently looked at another PHP frame, I suddenly felt a little puzzled.

In a Java-like application, the framework part of our package can be persisted in memory without having to load it every time. But PHP's mechanism is to request a single load at a time. So every request, to handle loading a configuration file, loading a bunch of packaged things is not a bit too wasteful.

Is that PHP also putting something in memory? For this piece please Daniel explain to explain.

First had to spit trough, PHP in this respect really "very weak", "very weak" does not mean that PHP really hate "bad", admittedly, PHP is the best dynamic template language.
PHP is a dynamic, interpreted language that provides very limited functionality in terms of language, which is probably why it is so easy to get started with PHP. So we groped/explored, summed up a lot of excellent frameworks (Yii, Zend framework ...), assembled a lot of awesome technology (Cache/queue/cluster/replication set/async/config System/log system/Monitoring System/automation ...) To this level is the confusion of the landlord (PHP framework of some doubts), the first to congratulate you, you at least to the PHP development of the intermediate level, many people are afraid to try. This confusion is a normal reaction. Because the understanding of more, you will think the whole process, if each request processing is so, indeed a bit of efficiency under, PHP at the code level (PHP5 collectively referred to as op+) provides accelerator/buffer, said can improve the performance of more than 30%+, used can pass. In fact, as early as a few years ago Laruence to reflect on this problem, and developed a YAF (framework in PHP when the start of the time has resided in memory), here I do not speak Yaf, interested you can go to see.

APC, Zend Optimizer Plus, PHP 5.5 opcache.
are precompiled files and opcode cache in memory, this is the usual way to solve your confusion, recommended appropriate use, you can speed up PHP 20%-300%.
But for both PHP and Java, the bottleneck is actually on the database IO, the file loading, configuration steps omitted, the general speed is not too much 20%-100%, especially the database operations frequently.

The main focus is that you ask questions, other irrelevant will not dabble.

PHP itself is not resident cache, and a request ends and PHP stops executing. This is the PHP feature, regardless of memory, concurrency, and so on.
But what you said.

"Then every request to handle loading a configuration file, loading a bunch of encapsulated stuff is not a bit too wasteful." ”

is not entirely accurate. The mainstream PHP framework is cached and the caching mechanism avoids the problem.

PS: See no one answer, estimate is written by the landlord "for this piece please Daniel explain to explain." " scare away, I'm not Daniel, a regular PHP programmer, hereby declare."

PHP has a Java bytecode-like opcode cache mechanism, and PHP files running in the server are cached in memory in the form of compiled opcode

Common opcode cache Reference wiki: PHP Accelerator list

PHP 5.5 After the official built-in Zend Optimizer.

So by the way, it is recommended that the configuration files, templates, etc. all exist in PHP format to maximize the use of opcode cache and reduce disk IO

Some fixed configuration items can be written into the Apache environment variables, PHP inside with $_env to read. Apache each fork out of a process, will bring these configurations, and is resident memory.

OpCode is a way of thinking, accelerate and the like can also. Just listen to Daniel's share and say it. Http://www.infoq.com/cn/presentations/php-project-control

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