Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I got error while run cron job using php, How to i fixed it?

Tags:

php

cron

$_SERVER['DOCUMENT_ROOT']/file.php: line 1: ?php: No such file or directory
$_SERVER['DOCUMENT_ROOT']/file.php: line 2: syntax error near unexpected token `0'
$_SERVER['DOCUMENT_ROOT']/file.php: line 2: `set_time_limit(0);'

the above error, i got while run cron,

  • how to fixed that?
  • and the path from document root
  • shall i give virtual path for that, like http://domain.com/file.php, and also am try this, but it ll return the error "Non such file directory"...

can anyone help me... Thanks in Advance..

Regards, Vinoth S

like image 389
VinothPHP Avatar asked Jan 08 '11 11:01

VinothPHP


People also ask

Can Cron run PHP script?

In Linux, you can schedule jobs to run automatically after a stipulated time by entering a command into the crontab file. In this step, you will instruct the crontab daemon to run your /var/www/html/tasks. php script after every minute.


2 Answers

You're directly invoking the .php file. The shell looks for a shebang and finds <?php which is not a valid command line interpreter.

You'll have to prefix your script with something like:

#!/usr/bin/php5

Or in your crontab:

* * * * * /usr/bin/php5 /path/to/the/script.php
like image 188
Linus Kleen Avatar answered Sep 28 '22 04:09

Linus Kleen


Thank u for all ur comments... its very useful to me... But i try the all the way, But my hosting domain ll not support, thats y i tried,

                          php -q /path/to/the/script.php

like that, its working fine,My cron now working fine... Thank u all...

Regards, Vinoth S

like image 44
VinothPHP Avatar answered Sep 28 '22 06:09

VinothPHP