Home  >  Article  >  Backend Development  >  Can PHP's singleton be saved until the second request is sent?

Can PHP's singleton be saved until the second request is sent?

WBOY
WBOYOriginal
2016-10-22 00:14:32996browse

What is the life cycle of a PHP singleton?
For example, I obtain a singleton in the first request, and then assign a value to the variable $a. In this way, can the $a variable be obtained during the second request?
Regarding this knowledge, experienced friends, do you have any excellent blog posts or books that you can recommend to learn from? Thank you very much?

Reply content:

What is the life cycle of a PHP singleton?
For example, I obtain a singleton in the first request, and then assign a value to the variable $a. In this way, can the $a variable be obtained during the second request?
Regarding this knowledge, experienced friends, do you have any excellent blog posts or books that you can recommend to learn from? Thank you very much?

Impossible, php is single process and single thread

The answer is no, because all variables have been released when the script ends.

I think you need to understand the life cycle of php

<code>    
  1. PHP是随着WEB服务器(apache)的启动而运行的;
  2. PHP通过mod_php5.so()模块和服务器(apache)相连
  3. PHP总共有三个模块:内核、Zend引擎、以及扩展层;
  4. PHP内核用来处理请求、文件流、错误处理等相关操作;
  5. Zend引擎(ZE)用以将源文件转换成机器语言,然后在虚拟机上运行它;
  6. 扩展层是一组函数、类库和流,PHP使用它们来执行一些特定的操作。比如,我们需要MySQL扩展来连接MySQL数据库;
  7. 当ZE执行程序时可能会需要连接若干扩展,这时ZE将控制权交给扩展,等处理完特定任务后再返还;
  8. 最后,ZE将程序运行结果返回给PHP内核,它再将结果传送给SAPI层,最终输出到浏览器上。
  
  
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn