Jump to content


Photo

[SOLVED] [Solved] cron


  • Please log in to reply
14 replies to this topic

#1 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 14 October 2006 - 09:41 PM

I dont know if i am in the right place to post this.

Ok i am trying to run a cron but keep getting a error come in my inbox. i am very new to using crons.

This is the error

/home/lostcity/public_html/crons/cron24r.php: line 1: ?: No such file or directory/home/lostcity/public_html/crons/cron24r.php: line 2: syntax error near unexpected token `('/home/lostcity/public_html/crons/cron24r.php: line 2: `$db->query("UPDATE users SET uAttackTurns=uAttackTurns+2 WHERE uAttackTurns<uAttackTurnsMax AND (uType=1 OR uType=2)");

This is my code

<?
$db->query("UPDATE users SET uAttackTurns=uAttackTurns+2 WHERE uAttackTurns<uAttackTurnsMax AND (uType=1 OR uType=2)");
?>

Any ideas?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 October 2006 - 10:05 PM

Does cron24r.php actually work when run directly, rather than as a cron task?
Legend has it that reading the manual never killed anyone.
My site

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 14 October 2006 - 10:07 PM

if you're trying to run the file directly in a CRON, you need to add this line to the top:

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

this tells the command line to parse the following PHP code with the php engine (as far as i know), in quiet mode which suppresses the headers.  the /usr/bin/php might need to change depending on your hosting setup.  check phpinfo() for the proper path if this doesn't work.

#4 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 14 October 2006 - 10:08 PM

yes it does.

a little more detail

i have the cronjob reading crontab.txt

crontab.txt contains the following

/home/lostcity/public_html/crons/cron24r.php

So it reads crontab.txt ok but it wont read cron24r.php

I dont understand why :(

#5 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 14 October 2006 - 10:10 PM

if you're trying to run the file directly in a CRON, you need to add this line to the top:

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

this tells the command line to parse the following PHP code with the php engine (as far as i know), in quiet mode which suppresses the headers.  the /usr/bin/php might need to change depending on your hosting setup.  check phpinfo() for the proper path if this doesn't work.


So i add that to crontab.txt or cron24r.php?


And thx for the replys

#6 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 14 October 2006 - 10:26 PM

ok i added that to cron24r.php

And now i dont get the error im my inbox but the database dont update :(

altho if i run cron24r.php on my browser it works fine and updates the database

Any ideas?

#7 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 14 October 2006 - 10:31 PM

are you connecting to the database in the cron24r.php?

add an or die() clause to your query.  any output from the script should go to your inbox.

#8 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 14 October 2006 - 10:33 PM

i am connecting to the database via a include file there is a or die in the include file

I dont get anything come in my email at all now - errors or sucseed

#9 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 15 October 2006 - 07:59 AM

ok sorted the cron prob

#10 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 15 October 2006 - 08:19 PM

Can you tell us what you did to fix it? It may help some poor soul in the future.
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#11 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 16 October 2006 - 10:51 AM

Well i just did what akitchin said.

if you're trying to run the file directly in a CRON, you need to add this line to the top:


Code:
#!/usr/bin/php -q
<?php
// php here
?>
this tells the command line to parse the following PHP code with the php engine (as far as i know), in quiet mode which suppresses the headers.  the /usr/bin/php might need to change depending on your hosting setup.  check phpinfo() for the proper path if this doesn't work.


But it worked fine for a few days then i started getting another error in my mailbox

This is the error

Error in argument 1, char 3: option not found Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]        php <file> [args...]  -a              Run interactively  -C              Do not chdir to the script's directory  -c <path>|<file> Look for php.ini file in this directory  -n              No php.ini file will be used  -d foo[=bar]    Define INI entry foo with value 'bar'  -e              Generate extended information for debugger/profiler  -f <file>        Parse <file>.  Implies `-q'  -h              This help  -i              PHP information  -l              Syntax check only (lint)  -m              Show compiled in modules  -q              Quiet-mode.  Suppress HTTP Header output.  -s              Display colour syntax highlighted source.  -v              Version number  -w              Display source with stripped comments and whitespace.  -z <file>        Load Zend extension <file>.

Anyone understand this? If so any ideas to fix it?

Thanks for your time

#12 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 October 2006 - 09:10 PM

as far as i know, it means that it thinks 'q' is an option that doesn't exist.  i've gotten that error before and frankly, i don't know why it comes back seeing as in the usage explanation it clearly shows 'q' as a legit option.

someone who's good with linux command line care to help out here?

#13 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 16 October 2006 - 09:20 PM

I'm afraid I don't see the -q switch in my php -h, and don't see any flags to enable when you ./configure, am I missing something?

And out of curiosity, why do we need to suppress headers? Are there even going to be any headers sent, since it's being run through the CLI?
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#14 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 October 2006 - 09:33 PM

the headers are sent regardless of being run by CLI or the web server unless the quiet mode is set, as far as i know.  i've used the -q option on plenty of servers, so i'm starting to wonder if it's only available on certain servers?

#15 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 26 October 2006 - 08:18 PM

Well i removed the "-q" from the script now and all is working fine.

Thanks guys




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users