icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » cron - running a PHP file

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old November 30th, 2005, 2:52 PM   #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:
<?php
function microtime_float() {
   list(
$usec$sec) = explode(" "microtime());
   return ((float)
$usec + (float)$sec);
}
$time_start microtime_float();
$thetime time();
// some more stuff...
Do I need to change something when running the job automated? I don't understand why it's not seeing the first '<'.

Cheers,
Brett
brettuzzi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old November 30th, 2005, 4:06 PM   #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?
brettuzzi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old November 30th, 2005, 8:31 PM   #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
__________________
Fw Web Solutions
http://fwwebs.com
fwwebs5 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 1st, 2005, 10:59 AM   #4 (permalink)
All Ur Base R Belong 2 Us
Excelling Contributor
 
mr_fern's Avatar
 
Joined in Feb 2005
Lives in Vegas & New York
824 posts
Gave thanks: 2
Thanked 6 times
what is your crontab line?
__________________
Nobody doing nothing
mr_fern is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 1st, 2005, 1:05 PM   #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
brettuzzi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 1st, 2005, 1:07 PM   #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
brettuzzi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 2nd, 2005, 6:05 PM   #7 (permalink)
Registered User
Seasoned Poster
 
Majd-GFX's Avatar
 
Joined in Sep 2004
58 posts
Gave thanks: 0
Thanked 0 times
just wondering, what did you use for your crontab line? wget /user/NAME/home/public_html/... right?
__________________
Majd-GFX is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 2nd, 2005, 6:11 PM   #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.
brettuzzi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On