Application template porting for Aliyun Ace

Source: Internet
Author: User
Tags bool error code file upload mixed relative aliyun

Aliyun Cloud Engine (ACE) is a linear scalable application hosting environment based on the flexible computing platform. Application template is that we learn from the industry's App store concept, simplifying the user to create the application of the steps to facilitate the application of the promotion. This article only describes the PHP application template porting, other languages please refer to the relevant documentation.

1. File, directory reading and writing

For security reasons, the ACE restricts local file reading and writing, user data is recommended in our OSS (open Storage services, high reliability and scalability of mass data storage), and file reading and writing requires the use of a unified interface provided by ACE. The ACE supports creating user data directories and also supporting creating directories on source code files.

PHP fread, Fwite has been closed by the ACE default, please use the following methods to implement.

< PHP

Class cefile{}




Function Write ($fileName, $content, $sync =0) file writes

$fileName file path (relative path) $content file content $sync Whether you need to sync to all Web side, to ensure multiple Web data synchronization, the default is set to 0 return True|false


Function Read ($fileName) reading file contents

$fileName file path (relative path) returns the contents of the file |false


Function Delete ($fileName) Delete file

$fileName file path (relative path) returns True|false


Member variable errno as error code

Member variable errmsg for debug with error message returned

?>

The ace file read and write method is as follows:

Creating Cefile Objects

$ce = new Cefile ();

File Write

$ce->write ($fileName, $content, $sync =0);

Read File contents

$ce->read ($fileName);

deleting files

$ce->delete ($fileName);

2. File Cache Deployment

The main purpose of file caching is to save the frequently accessed data in local files, when there is a request to access the data directly, to avoid the request of the database again I/O operations, reduce the load pressure of the database.

Aces deploy two instances by default for each application, and the request is routed to an instance of it when there is a request for access. Aces are scalable and can increase or decrease the number of instances as requests increase and decrease. To improve performance, Aces also have file caching capabilities, such as caching configuration information. When the user modifies the configuration file, the function of the file cache should be called to synchronize the configuration information between multiple instances.

Therefore, if you use file caching in your application, you must use the file read-write interface provided by Ace and use the method to read and write files. Use a file cache deployment to set the Write method $sync synchronization parameter to 1.

3. Memcache Cache Deployment

Memcache Cache Management is a AACE distributed caching service for developers to cache the user's key-value form of small data in a shared way to speed up data response and reduce the pressure of back-end data processing.

The Memchae in the ACE environment is enabled by default and provides 64M free of charge to users. If the user needs to use the Memcache cache, be aware of the following considerations.

The Memcache APIs supported by the ACE are as follows:

bool Memcache::init ()


array memcache::get (array $keys [, Array &amp; $flags])


bool Memcache::set (string $key, mixed $var [, int $flag [, int $expire]])


BOOL Add (String $key, mixed $var [, int $flag [, int $expire]])


bool Replace (string $key, mixed $var [, int $flag [, int $expire]])


bool Decrement (string $key [, int $value = 1])


bool Increment (string $key [, int $value = 1])


bool Delete (string $key [, int $timeout = 0])


bool Close ()

Memcache APIs that are not supported by Aces are as follows:

bool addserver* * (string $host [, int $port =


11211 [, bool $persistent [, int $weight [, int $timeout [, int $retry _interval [, BOOL


$status [, Callback $failure _callback [, int $TIMEOUTMS]]] []]]


bool connect* * (string $host [, int $port [, int $timeout]])


BOOL flush* * (void)


bool* *pconnect (string $host [, int $port [, int $timeout]])


bool setserverparams* * (string $host [, int $port =


11211 [, int $timeout [, int $retry _interval = False [, bool $status [, Callback$failure_callback]]]

Application if you use the Memcache cache, you must use the Memcache cache interface provided by the ACE. The Memcache cache usage is as follows:

< PHP

//Connection $mem = new Memcache (); Creates the Memcache object, and the internal access agent gets the address and ID $mem-&gt;init ();


//Save Data $mem-&gt;set (' key1 ', ' This is the ', ' 0, 60); $val = $mem-&gt;get (' Key1 ');


//Replacement Data $mem-&gt;replace (' key1 ', ' This is replace value ', 0, 60); $val = $mem-&gt;get (' Key1 ');


//save Array $arr = Array (' AAA ', ' BBB ', ' CCC ', ' ddd '); $mem-&gt;set (' Key2 ', $arr, 0, 60); $val 2 = $mem-&gt;get (' Key2 ');


//delete data $mem-&gt;delete (' Key1 '); $val = $mem-&gt;get (' Key1 ');


//Close connection $mem-&gt;close ();?&gt;

4. File Upload

Files uploaded via the Web are based on OSS storage (OSS is the open storage service provided by Aliyun, and users can use OSS to build multimedia sharing sites such as pictures, videos, personal/enterprise data backup, etc. based on large-scale data).

Due to the limitations of the Ace platform, the uploaded files cannot be stored locally, only in Oss, the upload file interface provided by Ace must be used, and the corresponding URL will be generated after the file is uploaded. PHP's Move_uploaded_file method is no longer available, please use ACE to provide the method.

The file upload method is as follows:

Move_uploaded_file ($tmp _name, $filename)

To be replaced by:

$ce = new Acestorage ();

$result = $ce->upload ($tmp _name, $filename);

# $rs 1 = $ce->errmsg (); Output error message

# $rs 2 = $ce->errno ();

$result for the returned attachment file path, you can access it directly, such as:

www.domain.com/aliyun_ce_storage/$filename

5. Picture thumbnail, watermark and other special problems

Subject to local file read and write conditions, such as image thumbnails, watermarks and other functions are not supported, we will support in the subsequent version.

6. Data Backup Recovery problem

ACE provides online backup data functionality, and when you create an application, you can choose a backup point in time.

If you want to export data from an application, you need to work with the database client tool.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.