What is the lifecycle of the PHP Singleton? For example, I obtain a singleton in the first request and assign a value to the variable $. In this way, can the $ a variable be obtained in the second request? What kind of excellent blog posts or... can you tell me about the lifecycle of the PHP Singleton?
For example, I obtain a singleton in the first request and assign a value to the variable $. In this way, can the $ a variable be obtained in the second request?
Do you have any excellent blog posts or books to recommend? thank you?
Reply content:
What is the lifecycle of the PHP Singleton?
For example, I obtain a singleton in the first request and assign a value to the variable $. In this way, can the $ a variable be obtained in the second request?
Do you have any excellent blog posts or books to recommend? thank you?
IMPOSSIBLE. php is single-process, single-thread
The answer is no, because all variables are released at the end of the script.
I think you need to understand the lifecycle of php.
1. PHP runs with the startup of the WEB server (apache); 2. PHP is connected to the server (apache) through the mod_php5.so () module. 3. PHP has three modules: Kernel, Zend Engine, and extension layer. 4. the PHP kernel is used to process requests, file streams, error handling, and other related operations. 5. the Zend Engine (ZE) is used to convert the source file to the machine language, and then run it on the virtual machine; 6. the extension layer is a set of functions, class libraries, and streams. PHP uses them to perform certain operations. For example, we need MySQL extension to connect to the MySQL database; 7. when ZE executes the program, it may need to connect several extensions. Then ZE gives control to the extension and returns the control after processing the specific task. 8. finally, ZE returns the program running result to the PHP Kernel. it then delivers the result to the SAPI layer and finally outputs the result to the browser.