Following on from running my first cron job with 1and1 hosting what I really wanted to do was to be able to run a php script, perl script or some other form of script on a timed basis. This article is a description of setting up a cron job on 1and1 hosting to run a simple "hello world" style example. I have the 1&1 linux business hosting package so can only confirm this example works with that.
First I set up my helloworld.php script, this was a simple script to create a file called helloworld.txt and write the words "hello world" to that file and save it.
<?php
// the filename
$filename = 'helloworld.txt';
// the content
$content = 'hello world';
// create the file
$f=fopen($filename, "wb");
fputs($f, $content);
fclose($f);
// now done
?>
I tested this file by running it on my server and it worked fine. I would recommend you do the same.
The next thing I had to do was log on to my 1and1 server using SSH, the program I use for this is PuTTY which I have been using since university and works well. You enter the username and password for FTP and SSH access to your site in the PuTTY command prompt and then are logged into the site. The next two steps you have to go through are:
- to find the location of your current directory: enter "pwd" to find this... mine was: "/kunden/homepages/XX/dXXXXXXXX/htdocs"
- to find the location of php on your machine to do this I entered the command "php -info" in the command prompt and looked for the location in the output which was: "/usr/local/bin/php" however due to the nature of 1and1 hosting the full path was actually "/kunden/usr/local/bin/php"
Now I had to create my crontab file. In the file below the 14 refers to the 14minutes past the hour, you can find out about the 4 *'s from the crontab page on wikipedia. So I entered the command "crontab -e" (which means edit crontab) and came to the VI editor which 1and1 use on their debian linux installation. In that line I entered the command: "14 * * * * /kunden/usr/local/bin/php /kunden/homepages/XX/dXXXXXXXX/htdocs/helloworld.php > /dev/null" all on one line. This command means at 14minutes past every hour on every day using the program found at /kunden/usr/local/bin/php execute the file found at /kunden/homepages/XX/dXXXXXXXX/htdocs/helloworld.php and send the output to the location /dev/null (which means get rid of the output). Using this command I found that on 1and1 hosting my helloworld.txt file was updated between 14 and 18minutes past every hour.
I know this description would have helped me had it been available when I was looking for information on running a php file through a cron job on 1and1. I hope it helps you.
In the Facebook Directory
So I have been working on my facebook cocktail application for a little over a week now having started it on the memorial day weekend. It allows you to do everything my cocktail site does and a little bit more including recommending a cocktail to a friend and seeing the most recently popular cocktails and the top 12 users yesterday. I actually have a bunch more ideas of what it could do like little graphs of the popularity of the cocktail over time and so on.
What is exciting is that in 3hrs I have added 300users to the application, now obviously rates won't stay that high but realistically most of the east cost wasn't browsing facebook when the app was approved and neither was the UK. It will be really interesting to see how things go over the next 24hrs.
The best news is I have log files tracking everything going on so I will be able to note down and describe what the growth of a facebook application looks like!
More posts to come down the line but I want to leave you with a thought. For my cocktail recommendations engine I now have a track... at a user level... of every cocktail viewed and rated, and at what level (pretty much tied to demographic too if I can get my ass in gear and pull that data). This recommendation engine can get much, much smarter :D
June 04, 2007 in API support on the web, apis, general comments, php | Permalink | Comments (1) | TrackBack (0)