Creative Commons License

Using Cron

Following my previous post about outputting RSS feeds to XHTML, I spent today doing two things: firstly, I worked at formatting the output to my page so that it displays as I like, which was quite easy. I wanted two columns, so I floated one column to the left and one to the right - nice and simple. I then fixed the overall width for the two columns and their height - which proves tricky to judge when you want the description of each item and not just the total! I put a fixed height of 500 pixels on the div tags, but the output sometimes exceeded this on some feeds. I vcan get round this in one of two ways: firstly, only use the title, or secondly, limit the character output - but that's for another day.

I then looked at the slightly harder part - automating the rebuilding of the feed output - as I believe is the case with Planet Jedimoose. I had found details of how to do this already. In the script I want to execute:

#!/usr/local/bin/php -q

And in Cron:

0 11 * * * /path/to/file.php >/dev/null 2>&1

The block of 5 numbers/asterisks denoting that the script be run on the hour, at 11 o'clock, every day, of every week, of every month. Unfortunately, I couldn't get this to work, so I emailed the web hosting company, who told me that I needed this in Cron:

30 18 * * * /usr/local/bin/php -qf

/home/busyscot/public_html/test/magpierss/jedimoose_rss.php

>/dev/null 2>&1

Ignore the change in time the script would run (in this case, 18:30 every day) - I was merely testing it at various intervals, and I just updated the time to approximately 2 minutes after I'd finished editing each time! Unfortunately, this didn't seem to work either, and no output from Cron had made its way into my email inbox; thus, I decided I needed to do some Googling. I found a nice resource which told me that what I needed to do depended upon whether my php was installed as an Apache module, or as compiled CGI. For compiled CGI, it said to do this:

#!/usr/local/bin/php -q

That would be in the executable file, and then this in Cron:

* * * * * php /path/to/your/cron.php

That would execute the file every minute of every day. So, I modified it to this:

30 * * * * php /path/to/your/cron.php

0 * * * * php /path/to/your/cron.php

It then told me to execute a shell command, which I ignored as I don't have shell access. It then stated that if you have php installed as an Apache module, you have to do something else to work.

Well, the above Cron command works - but phpinfo() shows that I have php installed as an Apache module - so I guess it works either way (surely you can't have both installed, can you?)!

There are currently no comments on this article.

Submit a Comment