Jump to content

Archived

This topic is now archived and is closed to further replies.

R1der

[SOLVED] [Solved] cron

Recommended Posts

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

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

Any ideas?

Share this post


Link to post
Share on other sites
Does cron24r.php actually work when run directly, rather than as a cron task?

Share this post


Link to post
Share on other sites
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
?>[/code]

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.

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
[quote author=akitchin link=topic=111511.msg451954#msg451954 date=1160863637]
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
?>[/code]

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.
[/quote]

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


And thx for the replys

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Can you tell us what you did to fix it? It may help some poor soul in the future.

Share this post


Link to post
Share on other sites
Well i just did what akitchin said.

[quote]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.

[/quote]

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Well i removed the "-q" from the script now and all is working fine.

Thanks guys

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.