In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
The main content of this article is "Life cycle case Analysis of Laravel". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the life cycle case analysis of Laravel.
Lifecycle An of Laravel
Everything in the world has a life cycle, and when we use any tool, we need to understand how it works, so it will be easy to use, and the same is true of application development. If you understand its principle, it will be easy to use.
Before we look at the life cycle of Laravel, let's review the life cycle of PHP.
The operation mode of PHP
The two operation modes of PHP are WEB mode and CLI mode.
When we type the php command on the terminal, we use CLI mode.
When using a Nginx or other web server as a host to process an incoming request, the WEB mode is used.
Life cycle of PHP
When we request a php file, PHP has five stages of lifecycle switching to complete the request:
1 module initialization (MINIT), that is, the initialization function of the extension specified in php.ini is called for initialization work, such as mysql extension.
2 request initialization (RINIT), that is, a symbol table initializing the contents of the variable names and values needed to execute the script, such as the $_ SESSION variable.
3 execute the PHP script.
4 request processing completed (Request Shutdown), the RSHUTDOWN methods of each module are called sequentially, and unset functions are called on each variable, such as the unset $_ SESSION variable.
5 close the module (Module Shutdown), and PHP calls the MSHUTDOWN method of each extension, which is the last chance for each module to free memory. This means there is no next request.
WEB mode is similar to CLI (command line) mode, except that:
The CLI mode will go through a full 5 cycles of each script execution, because your script will not have the next request after execution.
The WEB pattern may use multithreading to deal with concurrency, so life cycles 1 and 5 may be executed only once, repeating the life cycle of 2-4 when the next request arrives, thus saving the overhead of system module initialization.
You can see that the PHP life cycle is symmetrical. All that said is to locate where Laravel is running, and yes, Laravel is only running in the third phase:
Action
By understanding this, you can optimize your Laravel code and learn more about Laravel's singleton (singleton).
At least you know that every time the request ends, the variable PHP will unset,Laravel the singleton just the singleton during a request.
Your static variables in Laravel cannot be shared among multiple requests, because each request ends with a unset.
Understanding these concepts is the first and most critical step in writing high-quality code. So remember that PHP is a scripting language, and all variables will only take effect in this request, which will be reset the next time, unlike Java static variables, which have a global role.
Life cycle of Laravel
Overview
The life cycle of Laravel begins with public\ index.php and ends with public\ index.php.
Request process
The following is the full source code of public\ index.php, which can be divided into four steps:
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.