Documentation I/O processing for the SAE platform _php Tutorial

Source: Internet
Author: User
Tags save file
friends who have used the SAE platform should know that, for platform security reasons, the SAE limits the user's use of the local IO. However, for some of the traditional PHP projects, it may bring a lot of inconvenience, because they are more or less the operation of the local IO, like Smarty's compiled template. To solve this problem, SAE provides TMPFS functionality. TMPFS allows developers to temporarily read and write local IO via standard IO functions, which facilitates porting of many non-SAE projects.

But Tmpfs is not enough, from the name of the temporary file system, its lifecycle is the same as the PHP request, that is, when the PHP request is completed, all the temporary files written to Tmpfs will be destroyed. TMPFS is a local temporary file, not a shared storage, and the SAE is a fully distributed environment, so it is not possible to share operation files through TMPFS between different requests, depending on the SAE platform documentation.

Example: I would like to use TMPFS to make a counter (of course, you can also use the counter service provided by SAE)

The code is as follows:

 
    =sae_tmp_path. " /test.txt "
      
         (! (
           
              (,1
                
                  1 } < Span $n span>= (
                         
                           ++< span; Span>  
                               
                                  span $file span>,
                                   
                                      
                                      
                                        Span 14< span>    
                                        
                                      
                                   
                         
               
            
      

The discovery does not go into else, because the temporary file system does not exist at the end of each execution, so each time the code starts (and a new PHP request), the temporary file does not exist.

This means that the file cannot be shared with two files or a different time request between files.

In fact, to read the SAE documentation, it is not difficult to find the SAE provided by the wrappers

Kvdb--saekv://

SAEKV://is used to read and write Kvdb is primarily used to save persistent storage data, the most common scenario is to save the configuration file

This will meet our requirements for creating changes to the persistent save file.

It must be < span=""> done before using this service.

Here is the test code for the counter:

 
    = "Saekv://count.txt" 
      
         (! (
           
              ( , 1
               
                  1
                  
                   }< Span 7< span>  = (
                          
                           < Span 9< span> 
                            
                             
                               ++
                                
                                   (,
                                     
                                        }    
                                         
                                  
                               
                             /span>     
                    
                  
               
        

That's all you can do.

There are two ways to delete files as well

One is the native Delete method of PHP unlink ($file) on the line

Another is the KVDB database deletion method provided by SAE:

Code:

< span="">< span="">= "Saekv://count.txt"< span="">< span="">=  < span=""> < span=""> - < span="">  < span="">  < span="">  < span="">  < span="">   < span="">  (->delete ("Count.txt" < span=""> < span=""> < span="">   < span=""> "OK"  }< span="">    < span="">    < span=""> < span=""> "No "  }< span="">    < span="">   < span="">  < span="">

See the KVDB service documentation for details, Count.txt is the key value ...

Reference Documentation: SAE Platform documentation

http://www.bkjia.com/PHPjc/440414.html www.bkjia.com true http://www.bkjia.com/PHPjc/440414.html techarticle friends who have used the SAE platform should know that, for platform security reasons, the SAE limits the user's use of the local IO. But for some of the traditional PHP projects, may have brought a lot of not ...

  • 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.