PHP + MySQL-single instance mode of Waterloo

Source: Internet
Author: User

The Singleton mode is a common design mode in development. It generates unique objects for operation, which greatly saves system resources. However, unfortunately, he met the stubborn resistance of the PHP + MySQL combination, so that his hot techniques could not be used, or even put into a zombie situation.

What's going on? The premise of the singleton mode should also be mentioned.

First, the singleton mode application must be in a continuous application, which can be cross-page or cross-request. This is the best condition and has the greatest effect. However, PHP does not take the ordinary path. It is dedicated to making a sale with a hammer. Every time the page is accessed, it will automatically exit to clean up all the memory resources. The next time I access the page, I will try again and reinitialize the resources. PHP's personalization is too prosperous, and he is keen to repeat the construction. There is no overall picture at all. The Singleton model won't be able to get started where he can make the most achievements.

Second, in a single script running at the page level, the boring Singleton mode can only be used to mix up and eat, so it can also be accompanied by your favorite PHP. Who suddenly came to think of a MySQL, and it was so hot with PHP that it was very emotional. The small power that had made the singleton mode even overhead was almost ruined, basically being a zombie. MySQL database connection function mysql_connect has the native Singleton capability that makes the singleton mode chilling. The fourth parameter of this function is whether to set up a new connection flag. By default, this parameter is false, that is, as long as the function is called every time, as long as it is the same database, user name and password, each time the Returned Database handle is returned for the first connection. With such powerful built-in Singleton capabilities, how can we prevent the singleton mode from being connected by cold sweat.

Finally, things have not yet reached the worst. Although the singleton mode has encountered Waterloo in front of PHP + MySQL, the singleton mode is always a fixed work of the people who have officially compiled it, the vast majority of programmers still do not dare to fire him easily, even if it is installed in the PHP + MySQL team, it can also be fooled.

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.