I got error while run cron job using php, How to i fixed it?
$_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
- s开发者_Python百科hall 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
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
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
Adding #!/usr/bin/php5
to the top of your script as in goreSplatter's answer perfect for scripts your are writing to run on a single machine. If you want to ensure that the script will work on other machines that might have PHP installed elsewhere (such as /usr/local/bin/php5
), then you can make use of the env
command to search for php under the current user's $PATH:
#!/usr/bin/env php
Use this line of code for the cron set up. Also in your cpanel set an email id where you can get an email whenever cron execute successfully so that you know that you have successfully set a cron job.
wget -O - http://YOURSITE/cron.php?cron_key=abcd
精彩评论