<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[图解任务计划程序的妙用（WIN篇）]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Tue, 05 Dec 2006 03:06:59 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	作者： &nbsp; phpteam, &nbsp; ptker &nbsp; <br/> &nbsp;版权声明：可以任意转载，转载时请务必标明文章原始出处和作者信息及本声明 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;相信不少读者（PHP爱好者）在工作、学习的过程中经常抱怨：在WIN如何让PHP定时自动发信呢？？如何让MYSQL实现自动备份而无后顾之忧呢？？如果完全依靠手工进行当然也可以实现，但操作上似乎过于繁琐了一点！别着急，利用系统的任务计划程序(Windows &nbsp; 98称之为计划任务)可轻易解决这一问题。这一功能往往被很多用户忽略或者未曾想到：）。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;所谓任务计划就是由计算机自动调用用户事先设置好的应用程序，从而达到简化用户操作的目的。利用Windows &nbsp; 2000的任务计划程序（相当与*NIX下的cron程序，这里不再对其详述），我们可以安排任何脚本、程序或文档在最恰当的时候运行，从而满足自己的需要。下面以Windows &nbsp; 2000为例。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;具体来说，我们若需利用任务计划程序自动运行则应执行如下步骤： &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;1.单击“开始”按钮，然后依次选择“程序”→“附件”→“系统工具”→“任务计划”（或者是“设置”→“控制面板”→“任务计划”），启动Windows &nbsp; 2000的任务计划管理程序。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;2.在“任务计划”窗口中双击“添加任务计划”图标，启动系统的“任务计划向导”，然后单击“下一步”按钮，在给出的程序列表中选择需要自动运行的应用程序，然后单击“下一步”按钮。 &nbsp; <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;设置适当的任务计划名称并选择自动执行这个任务的时间频率(如每天、每星期、每月、一次性、每次启动计算机时、每次登录时等)，然后单击“下一步”按钮。 &nbsp; <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;此时系统将会要求用户对程序运行的具体时间进行设置，如几号、几点钟、哪几个时间段才能运行等，我们只需根据自己的需要加以设置即可。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;4.接下来系统将会要求用户设置适当的用户名及密码(如图5所示)，以便系统今后能自动加以运行。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;5.最后，我们只需单击“完成”按钮即可将相应任务添加到Windows &nbsp; 2000的任务计划程序中，此后它就会自动“记住”这个任务，一旦系统时间及相关条件与用户设置的计划相符，它就会自动调用用户所指定的应用程序，十分方便(每次启动Windows &nbsp; 2000的时候，任务计划程序都会自动启动，并在后台运行，确保用户的计划能够按时执行)。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;现在我们来测试一下刚才所建的任务是否成功，鼠标右键单击“php”程序图标(如图6所示)，在弹出的菜单里面选择“运行”。一般情况下程序图标只要这样激活运行就可以正常启动。如果运行失败可查看用户和密码是否设置正确，还有确定“Task &nbsp; Scheduler”服务是否已启动，本人当初就是为了节省系统资源把它关掉了导致运行失败，害我找了大半天。另外也可从“系统日志”里查看到底是什么原因造成运行失败的。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;好了，讲了这么多任务计划的应用，现在我们切入正题，下面将介绍两个例子： &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;一、让PHP定时运行吧！ &nbsp; <br/> &nbsp;1、 &nbsp; &nbsp; &nbsp; 编辑如下代码，并保存为test.php： <br/><br/><div class="code"> &amp;nbsp;&lt;br/&gt;&lt;br/&gt; &amp;nbsp;&amp;lt;?php &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;$fp &amp;nbsp; = &amp;nbsp; @fopen(&amp;quot;test.txt&amp;quot;, &amp;nbsp; &amp;quot;a+&amp;quot;); &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;fwrite($fp, &amp;nbsp; date(&amp;quot;Y-m-d &amp;nbsp; H:i:s&amp;quot;) &amp;nbsp; . &amp;nbsp; &amp;quot; &amp;nbsp; 让PHP定时运行吧！&#92;n&amp;quot;); &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;fclose($fp); &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;?&amp;gt; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp;&lt;br/&gt;</div><br/><br/> &nbsp;2、添加一个任务计划，在(如图2所示)这一步输入命令：D:&#92;php4&#92;php.exe &nbsp; -q &nbsp; D:&#92;php4&#92;test.php &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;3、时间设置为每隔1分钟运行一次，然后运行这个任务。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;4、现在我们来看看d:&#92;php4&#92;test.txt文件的内容时候是否成功。如果内容为如下所示，那么恭喜你成功了。 &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;2003-03-03 &nbsp; 11:08:01 &nbsp; 让PHP定时运行吧！ &nbsp; <br/> &nbsp;2003-03-03 &nbsp; 11:09:02 &nbsp; 让PHP定时运行吧！ &nbsp; <br/> &nbsp;2003-03-03 &nbsp; 11:10:01 &nbsp; 让PHP定时运行吧！ &nbsp; <br/> &nbsp;2003-03-03 &nbsp; 11:11:02 &nbsp; 让PHP定时运行吧！ &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp;二、让MYSQL实现自动备份变成可能！ &nbsp; <br/> &nbsp;1、编辑如下代码，并保存为backup.php，如果要压缩可以拷贝一个rar.exe： &nbsp;<br/><br/><div class="code"> &lt;br/&gt; &lt;br/&gt; &amp;nbsp;&amp;lt;?php &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;if &amp;nbsp; ($argc &amp;nbsp; != &amp;nbsp; 2 &amp;nbsp; &amp;#124;&amp;#124; &amp;nbsp; in_array($argv&#91;1&#93;, &amp;nbsp; array(&amp;#039;--help&amp;#039;, &amp;nbsp; &amp;#039;-?&amp;#039;))) &amp;nbsp; &#123; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;?&amp;gt; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;backup &amp;nbsp; &amp;nbsp; Ver &amp;nbsp; 0.01, &amp;nbsp; for &amp;nbsp; Win95/Win98/WinNT/Win2000/WinXP &amp;nbsp; on &amp;nbsp; i32 &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;Copyright &amp;nbsp; (C) &amp;nbsp; 2000 &amp;nbsp; ptker &amp;nbsp; All &amp;nbsp; rights &amp;nbsp; reserved. &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;This &amp;nbsp; is &amp;nbsp; free &amp;nbsp; software,and &amp;nbsp; you &amp;nbsp; are &amp;nbsp; welcome &amp;nbsp; to &amp;nbsp; modify &amp;nbsp; and &amp;nbsp; redistribute &amp;nbsp; it &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;under &amp;nbsp; the &amp;nbsp; GPL &amp;nbsp; license &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp;&lt;br/&gt; &amp;nbsp;PHP &amp;nbsp; Shell &amp;nbsp; script &amp;nbsp; for &amp;nbsp; the &amp;nbsp; backup &amp;nbsp; MySQL &amp;nbsp; database. &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp;&lt;br/&gt; &amp;nbsp;Usage: &amp;nbsp; &amp;lt;?php &amp;nbsp; echo &amp;nbsp; $argv&#91;0&#93;; &amp;nbsp; ?&amp;gt; &amp;nbsp; &amp;lt;option&amp;gt; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp;&lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;option&amp;gt; &amp;nbsp; can &amp;nbsp; be &amp;nbsp; database &amp;nbsp; name &amp;nbsp; you &amp;nbsp; would &amp;nbsp; like &amp;nbsp; to &amp;nbsp; backup. &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;With &amp;nbsp; the &amp;nbsp; --help, &amp;nbsp; or &amp;nbsp; -? &amp;nbsp; options, &amp;nbsp; you &amp;nbsp; can &amp;nbsp; get &amp;nbsp; this &amp;nbsp; help &amp;nbsp; and &amp;nbsp; exit. &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;&amp;lt;?php &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;&#125; &amp;nbsp; else &amp;nbsp; &#123; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$dbname &amp;nbsp; = &amp;nbsp; $argv&#91;1&#93;; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$dump_tool &amp;nbsp; = &amp;nbsp; &amp;quot;c:&#92;&#92;mysql&#92;&#92;bin&#92;&#92;mysqldump&amp;quot;; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$rar_tool &amp;nbsp; = &amp;nbsp; &amp;quot;d:&#92;&#92;php4&#92;&#92;rar&amp;quot;; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;@exec(&amp;quot;$dump_tool &amp;nbsp; --opt &amp;nbsp; -u &amp;nbsp; user &amp;nbsp; -ppassword &amp;nbsp; $dbname &amp;nbsp; &amp;gt; &amp;nbsp; ./$dbname.sql&amp;quot;); &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;@exec(&amp;quot;$rar_tool &amp;nbsp; a &amp;nbsp; -ag_yyyy_mm_dd_hh_mm &amp;nbsp; $dbname.rar &amp;nbsp; $dbname.sql&amp;quot;); &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;@unlink(&amp;quot;$dbname.sql&amp;quot;); &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;echo &amp;nbsp; &amp;quot;Backup &amp;nbsp; complete!&amp;quot;; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;&#125; &amp;nbsp; &amp;nbsp; &lt;br/&gt; &amp;nbsp;?&amp;gt; &amp;nbsp; &lt;br/&gt; &amp;nbsp; &amp;nbsp;&lt;br/&gt;</div><br/><br/> &nbsp;2、添加一个任务计划，在(如图2所示)这一步输入命令： &nbsp; <br/> &nbsp; &nbsp; &nbsp; &nbsp;D:&#92;php4&#92;php.exe &nbsp; -q &nbsp; D:&#92;php4&#92;backup.php &nbsp; databasename &nbsp; <br/> &nbsp;3、时间设置为每天运行一次，然后运行这个任务。 &nbsp; <br/> &nbsp;4、最后会在d:&#92;php4&#92;目录下生成一个以数据库名和当前时间组成的rar文件。 &nbsp; <br/> &nbsp;5、恭喜你！大功告成了！ &nbsp; <br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;当然备份方式有很多种，读者可按照自己喜欢的去做！ &nbsp; <br/><br/><br/><br/>Tags - <a href="http://www.dzhope.com/tags/msyql/" rel="tag">msyql</a> , <a href="http://www.dzhope.com/tags/%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E5%25A4%2587%25E4%25BB%25BD/" rel="tag">数据库备份</a> , <a href="http://www.dzhope.com/tags/php%25E8%2587%25AA%25E5%258A%25A8%25E5%258F%2591%25E4%25BF%25A1/" rel="tag">php自动发信</a> , <a href="http://www.dzhope.com/tags/%25E4%25BB%25BB%25E5%258A%25A1%25E8%25AE%25A1%25E5%2588%2592/" rel="tag">任务计划</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] 图解任务计划程序的妙用（WIN篇）]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>