<?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, 24 Nov 2011 19:37:08 +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 up virtual host on XAMPP (OSX)</title>
		<link>http://www.crankberryblog.com/2011/setting-up-virtual-host-on-xampp-osx</link>
		<comments>http://www.crankberryblog.com/2011/setting-up-virtual-host-on-xampp-osx#comments</comments>
		<pubDate>Thu, 24 Nov 2011 19:37:08 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=504</guid>
		<description><![CDATA[If you have decided to go with XAMPP on your OSX machine, then you have made the right choice as it works excellent on the Mac and has almost no limitations. Because of the file structure was not the typical WAMP or server setup I was used to it was a bit tricky at first. In case anyone else had trouble here's a quick tutorial on how to get it rolling.]]></description>
			<content:encoded><![CDATA[<p>If you have decided to go with XAMPP on your OSX machine, then you have made the right choice as it works excellent on the Mac and has almost no limitations. Because of the file structure was not the typical WAMP or server setup I was used to it was a bit tricky at first. In case anyone else had trouble here&#039;s a quick tutorial on how to get it rolling.</p>
<p>I&#039;ve got XAMPP installed in /Applications/XAMPP so for the rest of this blog I&#039;ll assume you did the same. Open up your Terminal which you can find under /Applications/Utilities/Terminal.</p>
<h2>Enable Virtual Hosting (vhost)</h2>
<p>To enable virtual host, navigate to the XAMPP folder by typing in:</p>
<pre>cd /Applications/XAMPP/</pre>
<p>This is the root for your XAMPP application, now navigate into the etc folder:</p>
<pre>cd /etc/</pre>
<p>Here you&#039;ll find a bunch of files which is really the configuration for your localhost server. What you need to edit is the httpd.conf file. You do so with the vi editor. Next I&#039;ll show you the series of steps to do so and do a quick comment explaining them using the # sign (which means don&#039;t type in the # stuff). Some of you may have read/write problems so just tag sudo infront like I did and type in your computer password.</p>
<pre># Open the httpd.conf file with the VI editor
sudo vi httpd.conf

# Find where the vhost module is and include it
/vhost

# You'll end up with a line like this:
# LoadModule vhost_alias_module modules/mod_vhost_alias.so
# (which is commented out)
# Hit i to go into edit mode
i

# Remove the hash at the beginning of that line
# Once you're done hit [ESC]
[ESC]

# Now we look for the second vhost line
/vhost

# If the above command lingers in the line you just edited
# keep hitting it until you find this
# Virtual hosts
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
# Hit i to go into edit mode
i

# Remove the hash at the beginning of the line with Include
# hit [ESC] when done
[ESC]
# Now save and exit the file
:wq</pre>
<h2>Creating Virtual Hosts</h2>
<p>Ok now you&#039;ll be back in the etc directory, now you have to add some virtual host for your machine. Navigate into the extra folder:</p>
<pre>cd /extra/</pre>
<p>Now we&#039;re going to edit the httpd-vhosts.conf file which tells the local which domains are virtual hosts. Once again we do so with the vi editor:</p>
<pre># Edit the httpd-vhosts.conf
sudo vi httpd-vhosts.conf</pre>
<p>At the top of the file you&#039;ll see a huge chunk of comments which is for you reference, navigate to the bottom by hitting Shift + G. By default you&#039;ll need this chunk of code:</p>
<div class="dean_ch" style="white-space: wrap;"># LocalHost &#8211; Default &#8211; Must KEEP<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;VirtualHost *:80&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerName localhost<br />
&nbsp; &nbsp; &nbsp; &nbsp; DocumentRoot &quot;/Applications/XAMPP/htdocs&quot;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;Directory &quot;/Applications/XAMPP/htdocs&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Options Indexes FollowSymLinks Includes execCGI<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AllowOverride None<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Order Allow,Deny<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Allow From All<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;</div>
<p>If you have it then you&#039;re fine, if you don&#039;t hit [i] and paste it at the bottom. This block basically tells the localhost that the address http://localhost leads to /Applications/XAMPP/htdocs, which is that orange/white screen default for XAMPP. You&#039;ll need to change the address if you&#039;ve installed it in a different directory.</p>
<p>Now after that chunk of code you can start creating virtual hosts. Instead of writing line by here&#039;s a chunk of code you can copy modify and paste in. This chunk is to define http://myhost.crankberry/ as my local Crankberry virtual host.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;VirtualHost *:80&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerName myhost.crankberry<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerAlias www.myhost.crankberry<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerAdmin webmaster@localhost</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; DocumentRoot &quot;/Applications/XAMPP/htdocs/crankberry&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; DirectoryIndex index.php</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;Directory &quot;/Applications/XAMPP/htdocs/crankberry&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Options Indexes FollowSymLinks<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AllowOverride All<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Order allow,deny<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Allow from all<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;</div>
<p>There&#039;s four lines in there you&#039;ll need to change. The second and third which indicates your virtual host names. You can create anything but don&#039;t create something like google.com because then you won&#039;t be able to actually access google. Then you have to change the Document Root and Directory URL to point to where it physically sits. Once you&#039;re done:</p>
<pre># Hit [ESC]
[ESC]

# Save and exit
:wq</pre>
<h2>Telling Your Machine You Have Virtual Hosts</h2>
<p>Now your virtual host is almost done, you just need to tell your machine that you have these virtual hosts setup and they need to direct to those path. You will need to edit your computer&#039;s hosts file, do so by using the VI editor again:</p>
<pre>sudo vi /etc/hosts
# Notice the / in front of etc, that means I'm looking into
# the root of the computer, not the etc folder in XAMPP</pre>
<p>Now we&#039;re going to define the virtual host on the localhost port which is 127.0.0.1:</p>
<pre># Navigate to the bottom
Shift + G

# Hit i to insert
i

# Type in the IP and your vhost
127.0.0.1 myhost.crankberry

# Hit [ESC]
[ESC]

# Save and exit
:wq</pre>
<p>After that you made need to restart your XAMPP, but for me if I navigate to http://myhost.crankberry on my browser it works like a charm. Give it a go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/setting-up-virtual-host-on-xampp-osx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intalling Sphinx on Wamp localhost (Windows)</title>
		<link>http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows</link>
		<comments>http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows#comments</comments>
		<pubDate>Sun, 03 Apr 2011 20:42:39 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=458</guid>
		<description><![CDATA[I recall the first time trying to setup Sphinx search on my Windows machine with Wamp it wasn't so obvious of how it was to be setup. Here's a guide in how to get it setup on you local machine. If you want to <a href="http://www.crankberryblog.com/2011/installing-sphinx-on-centoslinux-through-ssh">install Sphinx on Linux / Plesk</a> there's an article for that too.]]></description>
			<content:encoded><![CDATA[<p>I recall the first time trying to setup Sphinx search on my Windows machine with Wamp it wasn&#039;t so obvious of how it was to be setup. Here&#039;s a guide in how to get it setup on you local machine. If you want to <a href="http://www.crankberryblog.com/2011/installing-sphinx-on-centoslinux-through-ssh">install Sphinx on Linux / Plesk</a> there&#039;s an article for that too.</p>
<p>Here is my environment:</p>
<ul>
<li>Windows Vista</li>
<li>Wamp 2.0</li>
<li>Apache 2.2.11</li>
<li>MySQL 5.1.36</li>
<li>PHP 5.3.0</li>
<li>Sphinx 1.10</li>
</ul>
<p>First of all download Sphinx for Windows which can be found (<a href="http://sphinxsearch.com/downloads/beta/">http://sphinxsearch.com/downloads/beta/</a>). I downloaded Win32 binaries w/MySQL support version because I only work with MySQL. Once you got this you&#039;re ready to begin.</p>
<h3>How Does Sphinx Works</h3>
<p>In brief this is how Sphinx works. Sphinx creates a separate index of the table you want to search. Your PHP scripts calls the Sphinx API to search connecting to a specific port where Sphinx is listening to. Sphinx then searches its own index and does the search returning the result. Yes, the index has to be updated every time your update your original table. On my live environment I have a <a href="http://www.crankberryblog.com/2009/setting-php-cron-job-with-crontab">cron job</a> setup to reindex with Sphinx every so often.</p>
<h3>Step 1 Extract and Prepare Conf File</h3>
<p>Extract the files into any folder you want, I&#039;ve selected c:\sphinx\. The next thing you need to do is create a document in c:\sphinx\bin called sphinx.conf. This is the most important part as Sphinx actually acts based on the settings and parameters defined in this single document. Once you have created sphinx.conf in the bin folder copy the content from c:\sphinx\sphinx-min.conf.in (this is their provided sample file). It looks like:</p>
<pre>#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
	type			= mysql

	sql_host		= localhost
	sql_user		= test
	sql_pass		=
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306

	sql_query		= \
		SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS
		date_added, title, content \
		FROM table

	sql_attr_uint		= group_id
	sql_attr_timestamp	= date_added

	sql_query_info		= SELECT * FROM table WHERE id=$id
}

index test1
{
	source			= src1
	path			= @CONFDIR@/data/test1
	docinfo			= extern
	charset_type		= sbcs
}

index testrt
{
	type			= rt
	rt_mem_limit		= 32M

	path			= @CONFDIR@/data/testrt
	charset_type		= utf-8

	rt_field		= title
	rt_field		= content
	rt_attr_uint		= gid
}

indexer
{
	mem_limit		= 32M
}

searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= @CONFDIR@/log/searchd.log
	query_log		= @CONFDIR@/log/query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= @CONFDIR@/log/searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 0
	unlink_old		= 1
	workers			= threads # for RT to work
}</pre>
<p>These settings should cover most of what you&#039;re looking for in terms of setting up Sphinx. I&#039;ll try to run through everything as much as possible. There are more parameters and customization you can do by reading their documentation <a href="http://sphinxsearch.com/docs/1.10/">here</a>.</p>
<p><strong>source src1</strong></p>
<p>This section defines your SQL settings and what is needed to be index. So the first few lines sql_host, sql_user, sql_pass, sql_db is exactly your local host MySQL settings. The sql_port is defaulted to 3306. I haven&#039;t changed this setting for Wamp so that&#039;s where my port sits.</p>
<p>The sql_query is actually crucial. This is the query that you want Sphinx to do and build an index on. Its just like an SQL query you would do. Say my table people had columns: id, name, address, city, age, and joined (stored as time stamp) as follow: </p>
<table width="520" border="1" cellspacing="2" cellpadding="2">
<tr>
<td>id</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>age</td>
<td>joined</td>
</tr>
<tr>
<td>50</td>
<td>john doe</td>
<td>546 random st.</td>
<td>Vancouver</td>
<td>42</td>
<td>124568794562</td>
</tr>
<tr>
<td>51</td>
<td>amanda smith</td>
<td>
<p>3425 great ave</p>
</td>
<td>Vancouver</td>
<td>18</td>
<td>124568923423</td>
</tr>
<tr>
<td>52</td>
<td>justin heiber</td>
<td>352 awesome dr</td>
<td>
<p>Burnaby</p>
</td>
<td>56</td>
<td>124569000231</td>
</tr>
<tr>
<td>53</td>
<td>macy store</td>
<td>355 loser pl</td>
<td>Richmond</td>
<td>26</td>
<td>124569000352</td>
</tr>
</table>
<p>I want to be able to search for the people&#039;s name and address only so thats all I care about, but I have to include the id and the timestamp. You can also defined unsigned integer attributes. So my sql_query will be:</p>
<pre>sql_query		= \
		SELECT id, id AS id_attr, name, address, joined  \
		FROM people

sql_attr_uint		= id_attr
sql_attr_timestamp	= joined

sql_query_info		= SELECT * FROM people WHERE id=$id</pre>
<p>I&#039;ve defined the sql_attr_uint, sql_attr_timestamp, and sql_query_info. The sql_attr_uint is the unsigned integer attribute and it <strong>can&#039;t</strong> be the first column which is to define your id. The sql_attr_timestamp is the UNIX timestamp in your column. You can convert if you want but I usually store my dates in timestamp anyways. The sql_query_info is for testing purpose only. It is the query that retrieves the actual row after searching. You have to do this yourself in your PHP Script.</p>
<p><strong>index test1</strong></p>
<p>You can change the name of test1 to anything you want but for the sake of it I&#039;ll just leave it. The source is just the name of the section we did above. If you changed the name then you have to change it here. The path is where you want to store the indexed file on your site. So I&#039;ll store it in the site directory in a folder called sphinx: C:\Wamp\www\site\sphinx\test1. The remainder I left the same. I&#039;ve taken out the real time indexing because I&#039;ll be doing my own thing and I heard there were lots of limitations to it at this point, so its not my thing. If it floats your boat you can do some more research and look into it. Here&#039;s my index:</p>
<pre>index test1
{
	source			= src1
	path			= C:\Wamp\www\site\sphinx\test1
	docinfo			= extern
	charset_type		= sbcs
}</pre>
<p><strong>indexer</strong></p>
<p>This section defines the indexer. My database is big so I increased the mem_limit to 64M. Don&#039;t just go for a high or low number. Too low can hurt your searching and too high can hurt your server. Find the balance based on the size of your database.</p>
<p><strong>searchd</strong></p>
<p>This part defined the searchd which is the search application from Sphinx. Besides the log paths I didn&#039;t change anything else. The listen port is where you want searchd to listen in on for search queries. I left it at 9312 which is where I&#039;ll point my PHP script to later on.</p>
<p>Here is my sphinx.conf file:</p>
<pre>#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
	type			= mysql

	sql_host		= localhost
	sql_user		= test
	sql_pass		=
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306

	sql_query		= \
		SELECT id, id AS id_attr, name, address, joined  \
		FROM people

	sql_attr_uint		= id_attr
	sql_attr_timestamp	= joined

	sql_query_info		= SELECT * FROM people WHERE id=$id
}

index test1
{
	source			= src1
	path			= C:\Wamp\www\s\sphinx\test1
	docinfo			= extern
	charset_type		= sbcs
}

indexer
{
	mem_limit		= 64M
}

searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= C:\Wamp\www\s\sphinx\searchd.log
	query_log		= C:\Wamp\www\s\sphinx\query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= C:\Wamp\www\s\sphinx\searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 0
	unlink_old		= 1
}</pre>
<h3>Getting Sphinx Ready</h3>
<p>Now that you have prepared the Configuration file which is the hardest part of this then you&#039;re ready to begin. The first part you want to do is prepare the Sphinx index. Open up your command promt (Start > Search [cmd] > CMD.</p>
<p>In command promt navigate to your Sphinx bin folder by typing in <em>cd c:\sphinx\bin</em>. </p>
<p>Once there launched the indexer to build the index by typing in <em>indexer.exe &#8211;config c:\sphinx\bin\sphinx.conf test1</em>. Replace test1 if you changed the name of your index. If you don&#039;t get any errors and see some numbers run then you&#039;re fine. If you get a &#034;failed to write&#034; message it&#039;s because you don&#039;t have admin access to your machine.</p>
<p>Once the index is build you want to install Sphinx on your Windows machine as a service by typing <em>searchd.exe &#8211;install &#8211;config c:\sphinx\bin\sphinx.conf &#8211;servicename Sphinx</em>. It&#039;ll prompt you that the installation was successful.</p>
<p>Now you have to start the service you just installed. Go to control panel > administrative tools > services. Find Sphinx in the list. Click on it and on the left side you should see Start (on my machine that&#039;s where it is). Click on it and it should start.</p>
<h3>Testing Sphinx Out</h3>
<p>Go back to command prompt and test it out using search. So say I want to search my table for john doe I&#039;ll type <em>search sphinx.conf &#034;john doe&#034;</em>. That should return something for me. I can define the <a href="http://sphinxsearch.com/docs/1.10/matching-modes.html">matching modes</a> and which column to search as well such as <em>search &#8211;ext2 &#8211;config sphinx.conf &#034;@name john @address awesome&#034;</em>. If you are getting the results you want then you are ready to move forward into your PHP script.</p>
<h3>Sphinx and Your PHP Script</h3>
<p>You need the Sphinx API in your script for it to work so go to c:\sphinx\api and copy sphinxapi.php to your site directory. Include this file in your script and call on the class:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">require_once</span><span class="br0">&#40;</span><span class="st0">&#039;sphinxapi.php&#039;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//Sphinx</span><br />
<span class="re0">$s</span> = <span class="kw2">new</span> SphinxClient;<br />
<span class="re0">$s</span>-&gt;<span class="me1">setServer</span><span class="br0">&#40;</span><span class="st0">&quot;localhost&quot;</span>, <span class="nu0">9312</span><span class="br0">&#41;</span>;<br />
<span class="re0">$s</span>-&gt;<span class="me1">setMatchMode</span><span class="br0">&#40;</span>SPH_MATCH_EXTENDED2<span class="br0">&#41;</span>;</div>
<p>Noticed I have setServer pointing to the port I told Sphinx to listen to. The setMatchMode is just the matching mode you&#039;ll like to use. In my case I&#039;m using extended 2.</p>
<p>Now you can query search your Sphinx index with:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="co1">//Search Query</span><br />
<span class="re0">$result</span> = <span class="re0">$s</span>-&gt;<span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;@name $searchName @address $searchAddress&quot;</span><span class="br0">&#41;</span>;</div>
<p>The $result returned will not include the rows and columns of your actual table. It&#039;ll return the follow parameters (taken from <a href="http://php.net/manual/en/sphinxclient.query.php">php.net</a>):</p>
<table width="520" border="1" cellpadding="1" cellspacing="1">
<thead valign="middle">
<tr valign="middle">
<th>Key</th>
<th>Value description</th>
</tr>
</thead>
<tbody valign="middle">
<tr valign="middle">
<td align="left">&quot;matches&quot;</td>
<td align="left">An array with found document IDs as keys and their weight and attributes values as values</td>
</tr>
<tr valign="middle">
<td align="left">&quot;total&quot;</td>
<td align="left">Total number of matches found and retrieved (depends on your settings)</td>
</tr>
<tr valign="middle">
<td align="left">&quot;total_found&quot;</td>
<td align="left">Total number of found documents matching the query</td>
</tr>
<tr valign="middle">
<td align="left">&quot;words&quot;</td>
<td align="left">An array with words (case-folded and stemmed) as keys and per-word statistics as values</td>
</tr>
<tr valign="middle">
<td align="left">&quot;error&quot;</td>
<td align="left">Query error message reported by searchd</td>
</tr>
<tr valign="middle">
<td align="left">&quot;warning&quot;</td>
<td align="left">Query warning reported by searchd</td>
</tr>
</tbody>
</table>
<p>This means that $result['total'] will tell me how many results were found and $result['matches'] is where the id of the search results are stored. So here&#039;s a simple line to return all of the results:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#91;</span><span class="st0">&#039;total&#039;</span><span class="br0">&#93;</span> &gt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#91;</span><span class="st0">&#039;matches&#039;</span><span class="br0">&#93;</span> <span class="kw1">as</span> <span class="re0">$id</span> =&gt; <span class="re0">$otherStuff</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Get Column</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$searchColumn</span> = <a href="http://www.php.net/mysql_fetch_array"><span class="kw3">mysql_fetch_array</span></a><span class="br0">&#40;</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM people WHERE id=$id&quot;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Dump</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/var_dump"><span class="kw3">var_dump</span></a><span class="br0">&#40;</span><span class="re0">$searchColumn</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;No results found&#039;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></div>
<p>Notice that the mysql_query is the same as sql_query_info in sphinx.conf. What a coincidence eh? LOL. That is all and now you have a working Sphinx search system setup on your local machine. If you need to reindex your Sphinx you can do so without restarting the service. In command prompt just run <em>indexer.exe &#8211;config c:\sphinx\bin\sphinx.conf &#8211;rotate test1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<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>

