Singleton-when PHP is running, since each HTTP request corresponds to a database PDO connection object instance

Source: Internet
Author: User
When PHP is running, since each HTTP request corresponds to a database PDO connection object instance, is the singleton mode meaningful in PHP? When PHP is running, since each HTTP request corresponds to a database PDO connection object instance, is the singleton mode meaningful in PHP?

Reply content:

When PHP is running, since each HTTP request corresponds to a database PDO connection object instance, is the singleton mode meaningful in PHP?

PDO connection objects are different in each request, but note that the difference here is the PHP Object, not the actual database connection. In Persistent mode, although a new PDO object is created every time a request is made, these objects actually have a pdo extension that controls the underlying connection of the shared database.

The Singleton mode is of course very useful. In Singleton mode, you only need to build a PHP Object, not to mention whether the PDO in these objects has the underlying shared implementation, the optical Singleton can save the memory and other expenses of the object.

In addition, there are two concepts. You can't put it together. Some underlying implementations of PHP are not subject to the lifecycle control of PHP requests. You cannot consider the implementation of pdo extensions in the PHP request cycle.

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.