I got an error while running a cron job using php, How to fix this?

$_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 error above, I received at runtime cron,

  • How is this fixed?
  • and the path from the document root
  • I have to provide a virtual path for this, for example http://domain.com/file.php , and also try this, but it will return the error "Non such file directory" ...

can someone help me ... Thanks in Advance ..

Regards, Vinoth S

+4
source share
4 answers

Thanks for all the comments cheers ... it is very useful for me ... But I try completely, but my hosting domain ll will not support, thats y I try,

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

like that, his work is great, My cron is working fine now ... Thanks everyone ...

Regards, Vinoth S

+4
source

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

You need to attach the script to something like:

 #!/usr/bin/php5 

Or in your crontab:

 * * * * * /usr/bin/php5 /path/to/the/script.php 
+7
source

Adding #!/usr/bin/php5 to the top of your script, as in goreSplatter's answer , is ideal for scripts that you write to run on the same machine. If you want to make sure that the script will work on other machines where PHP can be installed elsewhere (for example, /usr/local/bin/php5 ), you can use the env command to search for php under the current user $ PATH

 #!/usr/bin/env php 
+1
source

Use this line of code to configure cron. Also in your cpanel set an email id where you can receive an email when cron is successfully executed, so that you know that you have successfully installed the cron job.

wget -O - http: //YOURSITE/cron.php? cron_key = abcd

0
source

Source: https://habr.com/ru/post/1334744/


All Articles