<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CrankBerry Blog &#187; Web Hosting</title>
	<atom:link href="http://www.crankberryblog.com/category/web-hosting/feed" rel="self" type="application/rss+xml" />
	<link>http://www.crankberryblog.com</link>
	<description>Sharing ideas on web design, development and the internet economy</description>
	<lastBuildDate>Thu, 22 Apr 2010 21:46:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting PHP cron job with crontab</title>
		<link>http://www.crankberryblog.com/2009/setting-php-cron-job-with-crontab</link>
		<comments>http://www.crankberryblog.com/2009/setting-php-cron-job-with-crontab#comments</comments>
		<pubDate>Thu, 01 Oct 2009 08:26:05 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=161</guid>
		<description><![CDATA[So you've created a PHP script that does something like clean your tables or compiles a report on some data. You want it to run it every 2 hours but you don't want to go to your computer every 2 hours. What should you do? Cron job using crontab is what you should do. Cron job is basically setting a timer on your server to run the script at a certain time that you please. Sounds easy enough, but how do you do it? Lets find out!]]></description>
			<content:encoded><![CDATA[<p>So you&#039;ve created a PHP script that does something like clean your tables or compiles a report on some data. You want it to run it every 2 hours but you don&#039;t want to go to your computer every 2 hours. What should you do? Cron job using crontab is what you should do. Cron job is basically setting a timer on your server to run the script at a certain time that you please. Sounds easy enough, but how do you do it? Lets find out!</p>
<p>The first thing you need to do is obviously create the PHP script. Before setting up the cron job test and see if the script produces the result you want. You don&#039;t want to schedule something and find out a year later that it wasn&#039;t doing anything.</p>
<p>Assuming you have that part laid out now you can move forward. Now to schedule a cron job just login to your server&#039;s admin control panel area and find the cron job/crontab setting. Here&#039;s where I found it in Plesk and Cpanel:</p>
<ul>
<li><strong>Plesk: </strong>Domains > *domain_name* > Scheduled Tasks > *domain_user*</li>
<li><strong>Control Panel:</strong> Advanced Tools > Cron Jobs > Advanced</li>
</ul>
<p>Try to play around if you couldn&#039;t find it as different versions and CPs name things differently. You&#039;ll know when you find it as it asks you for minute, hour, day, month, year and weekday.</p>
<h3>The Cron Job Command</h3>
<p>Let&#039;s talk about the command first. The command is the code to tell the server which code to run. There&#039;s four commands to choose from and you&#039;ll have to try them out to see which one works for you. Here are the commands.</p>
<div class="dean_ch" style="white-space: wrap;">lynx &gt; /dev/null -dump SCRIPT URL<br />
wget -q -O /dev/null SCRIPT URL<br />
fetch -o /dev/null SCRIPT URL<br />
curl -s -o /dev/null SCRIPT URL</div>
<p>So for example if I want to run a backup code for this blog I would plug the following for the command.</p>
<div class="dean_ch" style="white-space: wrap;">lynx &gt; /dev/null -dump &quot;http://www.crankberryblog.com/backup.php&quot;</div>
<h3>The Time Setting</h3>
<p>Now that you have the command down its time to tell the server when to run the PHP script automatically. So here are the options you can set:</p>
<p><strong>Minute: </strong>0 &#8211; 59<br />
<strong>Hour:</strong> 0 &#8211; 23<br />
<strong>Day: </strong>1 &#8211; 31<br />
<strong>Month:</strong> 1 &#8211; 12<br />
<strong>Day of the Week:</strong> 0 &#8211; 7 (0 and 7 both represent Sunday)</p>
<p>Now these settings don&#039;t seem too flexible at all, but wait! there&#039;s more! There are some additional settings that can be used.</p>
<div class="dean_ch" style="white-space: wrap;">0&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&nbsp; &nbsp; &nbsp; &nbsp;Run at zero<br />
*&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&nbsp; &nbsp; &nbsp; &nbsp;Run every x (x being the setting, * in days means run every day)<br />
0,15,30,45&nbsp; &nbsp; &nbsp; &#8211; &nbsp; &nbsp; &nbsp; Run every 0, 15, 30 and 45 of x<br />
*/15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&nbsp; &nbsp; &nbsp; &nbsp;Run every interval of 15 for x<br />
10-15&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&nbsp; &nbsp; &nbsp; &nbsp;Run it every value between 10 and 15</div>
<p>I&#039;m not sure if those settings are confusing or not. Here are some examples for you to better understand how the timing commands work.</p>
<div class="dean_ch" style="white-space: wrap;">*/10&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;- Run every 10 minutes<br />
0&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; */1&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;- Run every day<br />
30&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 2,4,6&nbsp; &nbsp;- Run every Tues, Thurs and Sat at 7:30<br />
0&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 10&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */2&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;- Run every second day at 10:00<br />
0&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 1&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; */1&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *&nbsp; &nbsp; &nbsp; &nbsp;- Run on the first of every month</div>
<p>There you have it. Setting up your PHP script to run automatically even when you&#039;re not there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2009/setting-php-cron-job-with-crontab/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
