Modify MySQL configuration so that blogs are posted regularly

Source: Internet
Author: User
Keywords mysql wordpress php

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

The PHP program is a script that executes only if the client triggers it. And a lot of web site construction process need timing function, such as the early morning database automatic statistical data. This article is to describe the use of MySQL event scheduling Event_scheduler implementation of the timing of the blog post.

WordPress Blog Data table For example to explain the principle (WP many personal webmaster are familiar with):

WordPress has a wp_posts table (for storing articles, multimedia files), this table has a field called Post_status (state). This field has several properties, where publish represents the publication, and draft represents the draft. If you can control at a certain point in time to change the draft to publish, then the status of this article from the draft into a release state it!

I found that the WordPress background does not seem to set the timing option, because PHP itself does not support timed execution.

What if the blog is to implement a timed letter?

① set the MySQL event scheduler. (after text)

② Manual data Table post_date fields after the draft is set in the background.

OK, do not cheat WordPress bloggers. Really want to do this webmaster is a second force, with Windows Live writer more convenient ...

This station uses thinkphp to write, backstage can publish regularly. PHP itself does not support timed execution, so it has the use of the MySQL event scheduler.

Cut to the chase.

① Open the database management panel and execute the following SQL.

1SHOW VARIABLES like ' Event_scheduler '

  

If the value of Event_schedules is off, it means that your database does not have the event scheduler turned on.

② to open the event scheduler. Execute the following SQL.

1SET GLOBAL Event_scheduler = On

In my experiment, I found a problem. If the database is restarted, then the Event_scheduler is turned off again. Where is the 365-day continuous stable database server?

③ Modify MySQL configuration file Mysql.ini, the default open Event_scheduler.

Locate the configuration file My.ini under the MySQL installation folder, and add a sentence below [mysqld]: Event_scheduler=on. This way the event Sheduler will start automatically when MySQL is started.

The MySQL configuration file for the Linux system is in the ETC folder, my.cnf file (Windows system is My.ini file). Linux under Find command.

④ Click into the data table where you want to perform a timed, execute SQL below this table.

DROP EVENT IF EXISTS icaigen_post;
CREATE EVENT Icaigen_post
On SCHEDULE EVERY SECOND
Do UPDATE sre_posts SET post_status = 0 where ID in (select a.ID to (select tmp.* from Sre_posts tmp) a where a.post_ Status = 1 and (A.post_time-unix_timestamp ()) < 0);

Explain: Icaigen_post is the name of the event, and the name is arbitrarily taken. The first line of code means if this event exists in the previous datasheet, delete it.

The third line on Schdule EVERY SECOND is a statement that performs a back (do) every 300s.

The point is this SQL statement.

1UPDATE sre_posts SET post_status = 0 where ID in (select a.ID to (select tmp.* from Sre_posts tmp) a where a.post_st ATUs = 1 and (A.post_time-unix_timestamp ()) < 0);

A temporary table is used, because MySQL does not allow the table to be modified after a lookup in a statement, so a subset is stored with a temporary table. This question cnblog on scroll specially described, I also learned from this. Reference:

Http://www.cnblogs.com/chy1000/archive/2010/03/02/1676282.html

Post_time is the posting time, Unix_timestamp () is the current timestamp, because my blog post time is timestamp, so here and time stamp comparison. When the current timestamp is greater than the timed time (publish time), Post_status = 1 (data field meaning, 1 for draft, 0 for publication) is modified to 0.

Because the event statement is executed every 30 seconds, the maximum error for posting the blog post is 30 seconds.

For more information about MySQL event, refer to this article:

Http://netzp.blog.sohu.com/103852537.html

Related Article

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.