Microsoft and open source Dry comparison of _php and ASP. NET difference in session implementation and management mechanism

Source: Internet
Author: User

Microsoft and open source Dry comparison of _php and ASP. NET difference in session implementation and management mechanism Preface:Because the developer to rely on tools to eat, May and development tools, language, environment spend more time than the wife and children, so each person more or less on their own food tools in the emotional with religious complex, in the rational and the buttocks to determine the brain interests around, this comparison is generally easy to be controversial, These comparisons do not take any prejudice and emotional color, mainly in their own work in the Youdao Yun notes the experience of the diary is mainly for I to study for reference, write a lot of references to the value of sharing out to the needs of the people reference, if there is any dispute I do not excuse. This only represents my own understanding of the impression.Session Chapter:PHP uses files to store session data by default, and ASP. NET is saved in IIS process memory by default

php Method Advantages:Stable and reliable is not easy to lose, Nginx or Apache server restart does not affect the session loss, the session is stable and reliable. The whole mechanism is simple and transparent, the user can directly delete the files in the Session directory to invalidate the session, it is easy to implement some of the special requirements of the ASP. Then must be forced to read the latest records from the database, if there is such contradictory performance optimization scenario design: If the user table users have the Balance field balance, to let user a log in their own background to see their balance is up to date, and do not want to each refresh face on the request once the database caused unnecessary pressure, The best way to do this is to save a user's record entity in the session, each time reading its own Balance field display from the session, it will not cause pressure on the database, only if the Balance field Balance changes immediately after the removal of the user's seesion and then forced him to read the latest database fields, but when other events occur such as: other users to a after the transfer to clear a cache, the system of refunds, deductions, rewards to the balance caused by changes in the balance to clear a cache, Because of the transparent mechanism of PHP directly delete the corresponding session file can be, but with IIS is very troublesome, because Microsoft is biased to the session in memory, closed into a black box and did not provide the corresponding operation interface is tragic, only through other methods curve the salvation.php Way Disadvantage:Performance is not as good as saving in memory fast, and produce a large number of small files, repeatedly created to delete these small files will cause disk fragmentation over time will slow down the performance of the entire disk, resulting in a large number of file handles occupy the operating system file handle, and thus affect performance, the increase in website traffic is a tragedy, It is possible to generate millions of small files in one directory, and running on Linux operating systems with all the files in mind can also greatly affect file system performance, which can severely slow down the performance of the entire operating system. So this default mechanism does not perform as fast as the default storage of IIS in process storage. Those who blow open source technology performance design than Windows advanced people self-face, recently in-depth understanding of LAMP,LNMP found that there are many outdated design can not keep up with the times, such as PHP can not use the real database connection pool and so many more serious problems than originally imagined, of course Like there will be a third-party non-mainstream toss-up alternatives, such as the use of memcache memory to save the session in memory is also possible, but need to hand-toss a bit. Support for PHP distributed session:In a high-concurrency server load Balancing environment, two nginx or Apache to share the session is usually stored in the database, and then different load hosts to connect a database to achieve, the database performance and read and write files actually no essential difference, stability is still strong, But performance remains a weakness.ASP. NET approach Benefits:Fast, no need to read and write disks obviously it's natural thatASP. NET Way Disadvantage:Very unstable, do not say restart the IIS Web site such extreme operations will lose the session, even if the configuration file changes Web. config or changing the DLL in the bin directory causes the site to recompile, which resets memory causing the session to be lost, which is why it is common to encounter a strange illusion that a tester is missing in a few seconds during ASP. Usually there are programmers in the frequent update program, as long as the update once the full loss of a session; Microsoft's solution is also simple enough to use a separate ASP. NET State Service status Services process to hold session information, note that the use of the ASP or the data stored in memory, is only a separate service process, By default, the information is stored across process communication by listening on the tcpip=127.0.0.1:42424 port, so that even if IIS restarts does not cause the user login session to be lost, the stability is resolved, and the data still exists within the intrinsic speed performance much higher than the PHP file storage scheme. and the status service each computer is installed by default, only need to start on the line. Convenience and performance has been thrown down PHP is not a level.ASP. NET distributed session implementation:In a highly concurrent server load Balancing environment, two IIS to share the session is very simple, only need to connect a state server together to share the session, with simple settings can let the state service to open the remote access function. Of course, ASP. NET also supports to save the session to the database, but very few people use this kind of scheme without much reason. Session Management Summary:can see PHP and ASP. Two different philosophical directions on the session management mechanism, PHP stability is easy to implement, preference for hard disk storage, Microsoft NET preferred memory storage, the difficulty is higher than PHP, which is the commercial software and open source free software more typical features, Commercial software is generally implemented in a way that is better than free things, packaging a black box for you to use directly, but the special needs of the inconvenient to engage in.

Microsoft and open source Dry comparison of _php and ASP. NET difference in session implementation and management mechanism

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.