| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#1 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Jul 2005
14 posts
Gave thanks: 0
Thanked 0 times
|
cron - running a PHP file
Hi,
I have a very simple script that connects to MySQL, performs some commands, etc. Nothing fancy - I know that it works, because when I put the file in public_html/ and run it, it sends me the e-mail I'm looking for. When I schedule it to run, I get this error: /home/username/TableOptimize.php: line 1: ?php: No such file or directory /home/username/TableOptimize.php: line 3: syntax error near unexpected token `$usec,' /home/username/TableOptimize.php: line 3: ` list($usec, $sec) = explode(" ", microtime());' The associated code is as follows: PHP Code:
Cheers, Brett |
|
|
|
|
|
#2 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Jul 2005
14 posts
Gave thanks: 0
Thanked 0 times
|
From what I can gather, cron interprets code as CGI.
I tried removing the <?php and ?> and adding #!/usr/local/bin/php but to no avail - it ignores that line and e-mails me the coding. How can I make it parse the file with PHP? ![]() |
|
|
|
|
|
#3 (permalink) |
|
Surpass Fan
On a golden path...
Joined in Nov 2003
432 posts
Gave thanks: 0
Thanked 0 times
|
Take a look at these options:
http://www.scripts.freemans-web.com/...opic.php?t=123 |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Jul 2005
14 posts
Gave thanks: 0
Thanked 0 times
|
Got it looked after, thanks guys.
I was informed by forums.devshed.com to remove the <?php ?> tags and put #!usr/bin/local/php or whatever my path to php was... I didn't realize that cron parses files automatically as CGI unless you direct it otherwise with the #! in the first line. Thanks for the help anyway, Brett |
|
|
|
|
|
#6 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Jul 2005
14 posts
Gave thanks: 0
Thanked 0 times
|
I should note for others the reason it wasn't working was that it parsed the file with PHP, but removing the <?php?> tags left it to treat the coding as HTML.
For all cron jobs coded in PHP, leave your <?php and ?> tags, but set your first line as: #!/usr/local/bin/php |
|
|
|
|
|
#8 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Jul 2005
14 posts
Gave thanks: 0
Thanked 0 times
|
30 5 * * 3 /home/username/cronjobs/TableOptimize.php
My PHP scripts for cron are beneath public_html in my cron folder, as there's no reason anyone else should ever need to run it in their browser. That particular one is set to run every wednesday at 530 server time (230am) my time. |
|
|
|