File I/O processing on the SAE Platform

Source: Internet
Author: User

Friends who have used the SAE platform should know that for the sake of platform security, SAE limits the use of local IO. However, this may cause a lot of inconvenience to some traditional PHP projects, because they all have more or less local IO operations, such as the Smarty compilation template. To solve this problem, SAE provides the TmpFS function. TmpFS allows developers to temporarily read and write local IO through standard IO functions, which facilitates migration of many non-SAE projects.

However, TmpFS is not enough. In terms of name, it is a temporary file system. Its lifecycle is the same as that of a PHP request, that is, when the PHP request is executed, all temporary files written to TmpFS will be destroyed. TmpFS is a local temporary file instead of shared storage, and SAE is a fully distributed environment. Therefore, you cannot share the operating file between different requests through TmpFS. For details, refer to the description of the SAE platform documentation.

Example: for example, I want to use TmpFS as a counter (of course, the counter service provided by SAE can also be used)

The Code is as follows:

 <? =SAE_TMP_PATH."/test.txt" (!(     (,1      1 }     =(     ++           (,     ?>

It is found that the temporary file system cannot be executed in else because the temporary file system does not exist after each execution, so it is determined at the beginning of each code (a new php request ), the temporary file does not exist.

That is to say, the file cannot be shared with two files or one file at different times.

In fact, it is not difficult to find the Wrappers

KVDB -- saekv ://

Saekv: // used to read and write KVDB. It is mainly used to save persistent storage data. The most common scenario is to save the configuration file.

This satisfies our requirements for creating and modifying persistent storage files.

You must first use this service.

The following is the counter test code:

 <? ="saekv://count.txt" (!( (,1      1 }      =(           ++     (,           }

In this way, you can.

You can delete files in either of the following ways:

One is php's native deletion method unlink ($ file ).

Another method is to delete the kvdb database provided by SAE:

Code:

 ="saekv://count.txt" = -> (->delete("count.txt"  "ok" }  "no" }

For more information, see the KVDB service documentation. count.txt is the key value...

Reference: SAE platform documentation

 

 

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.