PHP design Mode's memo mode

Source: Internet
Author: User
Tags vars

1. Norton Ghost's convenience and problems

Most of our win users have used Norton Ghost, as long as the current system backup to generate image files, such as the system poisoning or crashes, with Norton Ghost recovery back to the back of the time.

This can be said to be the basic principle of Memo (Memento) mode, first backup, need to restore. So the memo mode is better understood.

However, in practical application, it is necessary to pay attention to how to apply the memo mode correctly.

When we write the article in Word, Ghost to back up all the hard disk, once the article is wrong, need to recover, use ghost to overwrite the hard disk?

Just like some website backup system, do is full station recovery, although convenient, but his backup and recovery scope and Norton Ghost is similar.

If you only adjust the style of a page's page list, you encounter the following issues:

1, 99% of the data has not changed, that is, 99% of the backup and recovery are redundant

2, full-site backup and recovery, the pressure on the server is very large, and even drag down the server

3, the execution time may be very long

4, the whole station data operation, once the halfway operation failed, you have to start again

2, PHP development of "undo" function

We usually use a lot of software to provide a call "undo" or "undo" function, you can undo the previous operation, then we develop PHP can also learn from.

This allows us to better apply and understand the memento model, as backup and recovery can be done on a variety of grain size.

Cases:

  1. <?php
  2. //Memo class  
  3. class Memento
  4. {
  5. Public function backup ()
  6. {
  7. //Save an existing page-out style  
  8. Echo ' style has been saved <br> ';
  9. }
  10. Public function restore ()
  11. {
  12. //Use a saved style to overwrite  
  13. Echo ' style has been restored <br> ';
  14. }
  15. }
  16. //Set pagination style  
  17. class ListStyle
  18. {
  19. //Memo Object  
  20. Private $memento;
  21. //Construction method  
  22. Public function __construct ()
  23. {
  24. $this ->memento = New Memento ();
  25. }
  26. //Set style  
  27. Public function setStyle ()
  28. {
  29. //Start back up style first  
  30. $this ->memento->backup ();
  31. //Set style  
  32. Echo ' Set the style <br> ';
  33. }
  34. //Undo Method  
  35. Public function undo ()
  36. {
  37. $this ->memento->restore ();
  38. }
  39. }
  40. $listStyle  =  New ListStyle ();
  41. //Set style while backing up  
  42. $listStyle ->setstyle ();
  43. //Undo Settings  
  44. $listStyle ->undo ();
  45. ?>

This eliminates the need to backup and restore the entire station.

2, PHP development of "redo" function

We implemented the "undo" function in front of the other software, which corresponds to the "redo" function, usually called "redo".

So we need to improve the code.

Cases:

  1. <?php
  2. //Memo class  
  3. class Memento
  4. {
  5. Public function backup ()
  6. {
  7. //Save an existing page-out style  
  8. Echo ' style has been saved <br> ';
  9. }
  10. Public function restore ()
  11. {
  12. //Use a saved style to overwrite  
  13. Echo ' style has been restored <br> ';
  14. }
  15. }
  16. //Set pagination style  
  17. class ListStyle
  18. {
  19. //Memo Object  
  20. Private $memento;
  21. //Construction method  
  22. Public function __construct ()
  23. {
  24. $this ->memento = New Memento ();
  25. }
  26. //Set style  
  27. Public function setStyle ()
  28. {
  29. //Start back up style first  
  30. $this ->memento->backup ();
  31. //Set style  
  32. Echo ' Set the style <br> ';
  33. }
  34. //Undo Method  
  35. Public function undo ()
  36. {
  37. //Save first, for redo  
  38. $this ->memento->backup ();
  39. $this ->memento->restore ();
  40. }
  41. //Redo Method  
  42. Public function redo ()
  43. {
  44. $this ->memento->restore ();
  45. }
  46. }
  47. $listStyle  =  New ListStyle ();
  48. //Set style while backing up  
  49. $listStyle ->setstyle ();
  50. //Undo Settings  
  51. $listStyle ->undo ();
  52. //Redo Settings  
  53. $listStyle ->redo ();
  54. ?>

In this way, we can provide a detailed implementation of the memo mode. more PHP Tutorial , please visit the Code home ;

Thinking:

Memo mode is a common mode, especially in software development, for PHP, can also be used in some situations.

But PHP's memo mode, often need to pay attention to the feasibility, because the software, such as word, are single-machine-based, and PHP's Web site is often accessed by many users simultaneously.

A lot of access, if the backup at this time, the server can withstand? How do I resolve data consistency for concurrent access?

Although this paper discusses the application of fine and independent memo mode, it is necessary to apply different strategies according to the specific situation in practical application.

This article original address:http://www.daimajiayuan.com/sitejs-16852-1.html

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.