FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Question: PHP scripting + cron jobs





hyhy
Hi i would like to use cronjobs to open my php script which read 4 rss feeds. And here's my question: If i enter in cron jobs that task and i put it on every 2 minutes is it ok? I mean won't it take too much of hosting CPU or so? If then, then is 5 mins ok? or 10?
Teddy1
As there is a rule against posting a topic with the same subject i'll post my problem here too.

I'm having trouble with the cronjob executing a php script, i can get it to execute at the given times but the php script does not successfully execute, i get this error from the log that is emailed to me via the cronjob.
i have looked for a `newline' on line 1 but i can't find it or nor do i have any clue what to do Confused please help.

error returned in email :
/bin/sh: -c: line 1: syntax error near unexpected token `newline'
/bin/sh: -c: line 1: `/home/teddy1/public_html/Bnt/scheduler.php?password=<swordfish>'

Thanks in advance
Teddy1
Manofgames
what are cron jobs???
hyhy
Manofgames wrote:
what are cron jobs???


There's a search option up there in the links.

But i will be nice ang give you straight link:

!! SEARCH !!

You can also try:

!! GOOGLE !!

Or just ask in proper place on forums, not in my topic!
Teddy1
why not explain for the fella?, cron jobs execute a command at a set interval for example lets say you wanted to execute a php script every five minutes you would make one for that and then you set to "*/5" that's for this particular host it's different with each hosting server. you also have to set the path for this particular file, that pretty much sums up what a cron job does. need anymore info then google is your answer. Wink
Daniel15
Quote:
Hi i would like to use cronjobs to open my php script which read 4 rss feeds. And here's my question: If i enter in cron jobs that task and i put it on every 2 minutes is it ok? I mean won't it take too much of hosting CPU or so? If then, then is 5 mins ok? or 10?

Every 2 minutes is probably a bit excessive (would the RSS feed really be updated that often?). 10 minutes would probably be fine Wink

Teddy1 wrote:
As there is a rule against posting a topic with the same subject i'll post my problem here too.

I'm having trouble with the cronjob executing a php script, i can get it to execute at the given times but the php script does not successfully execute, i get this error from the log that is emailed to me via the cronjob.
i have looked for a `newline' on line 1 but i can't find it or nor do i have any clue what to do Confused please help.

error returned in email :
/bin/sh: -c: line 1: syntax error near unexpected token `newline'
/bin/sh: -c: line 1: `/home/teddy1/public_html/Bnt/scheduler.php?password=<swordfish>'

You can't pass arguments to it like you have... The command needs to look like:
php -q /home/teddy1/public_html/Bnt/scheduler.php
If the only use for that password is to stop normal visitors running the script, do something like:
Code:

<?php
if(isset($_SERVER["HTTP_HOST"])) {
    echo "This script is meant to be run as a cron job - You can't run it manually!
}

// Rest of your script here
?>

Basically, if someone tries to visit http://[yoursite].frih.net/Bnt/scheduler.php, they'll get the error. However, if it's run by the cron job, it will work fine.

If you still need to pass GET variables, use a command like:
Code:
wget http://[yoursite].frih.net/Bnt/scheduler.php?stuff=yes > /dev/null

This will run the script as if someone visited the page in a web browser. For this to work, you can't use something like the code I posted above.
Teddy1
Thank You! Very Happy, haven't tried either but both sound like they would work. If they do i will donate Smile
Teddy1
For the first one i get this error

/bin/sh: line 1: php: command not found

i'll keep you posted about the second one. Smile
Teddy1
Tried with second one and got this. Can you verify please
Code:

--17:12:00--  http://teddy1.frih.net/Bnt/scheduler.php?swordfish=*****
           => `scheduler.php?swordfish=*****'
Resolving teddy1.frih.net... 216.32.85.170
Connecting to teddy1.frih.net|216.32.85.170|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ........                                                  3.78 KB/s

17:12:03 (3.78 KB/s) - `scheduler.php?swordfish=*****' saved [9048]
Teddy1
The update is working, I want to thank you soo much Very Happy. Donation sent Very Happy
Teddy1
Is there a possible way to get the newly created files into a specific directory so i can just delete them easier ? after the updates have happened as it takes a long time for me to delete them lol, but i much appreciate what you have done thanks Smile
Bondings
For cron jobs, please don't put them more frequently than every 10-15 minutes. And definately don't execute heavy tasks that frequently.
Daniel15
Teddy1 wrote:
Is there a possible way to get the newly created files into a specific directory so i can just delete them easier ? after the updates have happened as it takes a long time for me to delete them lol, but i much appreciate what you have done thanks Smile

Oh, I didn't think of that Razz I'm actually not sure of how to solve it.

You could try the first method I posted again, but try something like: /usr/local/bin/php -q /home/teddy1/public_html/Bnt/scheduler.php (because just 'php' didn't appear to work). If /usr/local/bin/php doesn't work, try /usr/bin/php
Teddy1
I just use FTP to delete the unwanted files, Thanks for the help Smile
Teddy1
I did try your 3rd and 4th method, but still no success. So i went back to the method that did work. Thanks for your help Smile
Daniel15
Sorry about that, I found the way to fix it... Seeing as WGET worked for you, the command should be:
Code:

wget -O - -q http://[yoursite].frih.net/Bnt/scheduler.php

Wink
Teddy1
Thanks i'll try and give you the result. Smile
Related topics
Cron Jobs
Cron jobs - running a php file
[PHP] Running Cron Jobs Via PHP Script
Executing automated tasks without using cron jobs
cron jobs?
Problems With Cron Jobs
Enabling Cron Jobs
CRON Jobs
how do cron jobs work?
Cron jobs on DirectAdmin
Cron jobs and PHP?
Cron jobs
Has anyone installed Moodle successfully?
Repetitive Events Without Cron Jobs
Reply to topic    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.