Small Ant Learning App Interface Development (4)--static cache operation method and timed task

Source: Internet
Author: User

Statically cached operations

This previously written page static has a similar idea, nothing more than to get the data, write data, read the data, a few actions. The example writes a method, through to the parameter judgment, can the static cache file generation, the modification and the deletion, is relatively easy to manipulate.

<?phpclass file{//the path to the cache file private $_dir;//the default path to the cache file const ext= '. txt ';//construction Method Generation directory Function _ _construct () {$this->_dir=dirname (__file__). ' /files/'; if (!is_dir ($this->_dir)) {mkdir ($this->_dir,0777);}} /*************************** cache file generation, modification, deletion * $value have value, write. No value, read out. NULL, delete * @param   string$key  file name  * @param   mixed$value  Cached data * @param    string$path  path to the cache file *return  mixed  return value is Boolean, String, Integer ********************/public  Function catchdata ($key, $value = ', $path = ') The full path of the {//cache file $filename= $this->_dir. $path. $key. self::ext;// If value is null, this deletes this static cache if (Is_null ($value)) {return  @unlink ($filename);} If $value is not equal to NULL, the description is the write operation if ($value  !=  ") {//To determine if the submitted path exists $dir =dirname ($filename); if (!is_dir ($dir) ) {mkdir ($dir, 0777);} Data json, saved to file Return file_put_contents ($filename, Json_encode ($value));} ElseIf ($value  ==  ") {    //description is read operation if (Is_file ($filename)) {Return json_decode (File_get_contents ($filename), true);} Else{return false;}}}} $file  =new file (); $str = $file->catchdata (' MyBlog ', ' learn php ' little ant   blog  http://my.oschina.net/ Woshixiaomayi/blog '), if ($STR) {if (Is_bool ($STR)) {echo  ' Success ';} else{echo  $str;}} else{echo  ' error ';}? >

The main judgement is the second parameter $value, if there is a value, then write, if no value, read, if it is null, delete;

Set a scheduled task on a Linux system

Command: 1. CRONTAB-E editing a user's cron task

2. Crontab-l list details of a user's cron service

3. Crontab-r Delete a scheduled task

Format of timed tasks

Time-Sharing Week order

*            *            *            *            *

0-59 0-23 1-31 1-12 0-6 command

Note: * represents values within the range of the number/representative of each, e.g. per minute

For example:

*/1 * * * * php/data/www/index.php execute index.php script per minute

7 * * */sbin/service sshd start daily 7:50 open SSH service

Small Ant Learning App Interface Development (4)--static cache operation method and timed task

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.