PDA

View Full Version : Back-end automated script


davidshaw89
9th January 2009, 11:48
Hi everyone,

I am looking to create a script for the back-end of a website, but I want this to run at set times throughout the day/week/month even when I can't be at a computer.

Does anyone know what this is called? and if I need to use certain programming languages for it?

Basically I want the website to automatically delete records from a MySQL database when they become obselete without any human interaction.

Thanks in advance,

drkm
9th January 2009, 11:51
If it's running on unix you can use crontab and have the script executed from the command line.

davidshaw89
9th January 2009, 11:54
Thank you - yes it is on a unix server.

What languages could I use for writing the script?

zoezoe
9th January 2009, 12:00
if you need soem help here we can write this type of script in PHP and schedule it so that it performs this taks. Might be cheaper than trying to figure out how to do this yourself? do you know MYSQL ?

davidshaw89
9th January 2009, 12:05
So I can execute a php script from crontab?

If so, that is such a relief since I can write it in PHP myself no problem.

silklink
9th January 2009, 12:06
Alternatively, google PHP scripts to automate or manipulate MySQL records.

I'm making the assumption that you have a Unix/Linux based host and you are running MySQL???

davidshaw89
9th January 2009, 12:07
I'm making the assumption that you have a Unix/Linux based host and you are running MySQL???

yes that is right. Thank you

ozbon
9th January 2009, 15:00
You need to make sure that the PHP script being called by crontab runs as a CGI, because it's not going to run through the normal web-browser.

Sitepoint has a useful piece on setting up a PHP script using cron (http://www.sitepoint.com/article/introducing-cron/)

davidshaw89
9th January 2009, 16:06
Thank you all for the advice.

If I can hopefully get Crontab to execute a simple php script successfully it could mean that I can actually automate a lot more of the processes than initially planned through the night instead of daytime when the server is busy.

Much appreciated

FireFleur
9th January 2009, 23:10
Be careful, it is not CGI which is the Common Gateway Interface used in webservers.

If you have to use PHP and this is something that has been added, it is more aking to running PHP as an application, some call it PHP shell scripting.

The CGI mentioned is sort of the steps to take, but ironically it is without the CGI so don't go placing it in directories that can be accessed via the web, otherwise it becomes potentially accessible via the web.

You create a file and add a shebang line e.g.

#!/usr/bin/php -q
<?php

print "It works!\n";

... code goes here

?>

Then chmod 700 the file.

Then execute it to see it works so

./file.php

Personally I would use something else, but if PHP is your bag then it should be ok.

You will have to include various things to gain access to the DB, and any modules you have been using will have to be introduced - and this is where the CGI idea springs in, there is crossover in how you do it.

I notice the link given doesn't use a shebang, that may not be necessary nowadays, as I say I don't really use this feature of PHP, or PHP much for that matter nowadays :)