Hello, Can anybody give me some idea on how to do cron jobs? What is the file extension? Where will it be placed? Any basic sample code? Thanks in advance!
Here is a guide on setting up cron jobs: http://www.adminschoice.com/docs/crontab.htm#Example I hope this helps.
If you have cpanel you can set them in there using the cron job in the dashboard It's really easy to use
Thanks but what i wanted to know is how to do it in a script as I need to add a cronjob to an autoblog script that i made. Anybody can teach me how to do that? Can I add cron jobs in a script? Will appreciate any help. Thanks! I already made one but it's not actually a cron job as site needs to be visited to be activated.
If the site needs to be visited then just issue a wget command, so for example: note - the hxxp is only cause I can't post links yet
Yeah, that's currently what i made. But, I'm trying to find a way where it will be a cron job that will not rely to visits. Can anybody help? Thanks!
Create a script that runs on your own cron job every minute, then with that script, run crons depending on if enough time has passed since the last time it was run
I'm guessing since you want this to happen via scripting that you want to do this quite flexibly, so consider using a database to read all the cron commands and the time periods between them
Yeah, that's exactly what i want to make. Can you teach me how to call a cron via a script? and how will i make the cron the i'll be calling via a script? Can you at least teach me some basics? Thanks!
Set up your PHP script: // Do Cron stuff here PHP: Save it somewhere accessible: /home/myhost/public_html/cronscripts/myscript.php Code (markup): Then set up a cronjob with the following parameters: * * * * * php /home/myhost/public_html/cronscripts/myscript.php Code (markup): Glossary: * * * * * Every second 0 * * * * Every minute (at 0 seconds) 0 0 * * * Every hour at (0 minutes, 0 seconds) ... and so on (refer to a CRON manual) Code (markup): To test if it works, have it send you an email every time it runs (and disable the code when you confirm that it works, otherwise you'll be swamped): // Do Cron stuff here // Mail to confirm mail('my@email.com', 'Cronjob Ran!', 'The cronjob worked'); PHP:
if you're going to use php as a shell script, make sure trhe she-bang (or whatever it was called) is present in the php script header, just as you would in perl or bash: #!/usr/bin/php <?PHP .... ?> PHP: also make sure you chmod it to 755 or something to allow execute
try some online cron jobs service such as www.setcronjob.com, onlinecronjob.com, webcron.org. You can set up cron jobs to call your URL periodically. It's very easy, as all of those have web cron interface.
No, the hashbang (#!/usr...) only applies to shell scripts. You can't execute PHP scripts natively in the shell. What this does: php myscript.php Code (markup): ...is start PHP with "myscript.php" as a parameter. There don't have to be any special permissions on myscript.php in order to get it to run. All of this only applies to shell scripts, which need the hashbang, and need chmod +x in order to be executed like this: ./myscript.sh Code (markup):
cron job is not a file... it is a service ,which is provided by the hosting server.if u r using in CPANEL then go to cronjob tab and give the URL of your file which u want run at a specific time.or if u use plesk then goes to crontab link and set timing and file path
What about securities? It seems to me that anyone who somehow knows the location of the PHP script can access that page via browser and cause functions to fire. Are there anyway to prevent this so that PHP script can only be used with cron?
yeah, code it so it checks browser string, if any (i.e. not triggered by cron as a shell script), just do a 'die'.
Set a password, and it will be fine put this into your php file: <?php if($_GET['password']!='SECRET') exit('Access denied.'); ?> PHP: Then just set cron job with yoursite.com/script.php?password=SECRET