0

Until now I am using the simple line within cron: php somefile.php

Now I found that there is a sha-bang: #!/bin/php added to the very first line of the php file and to my understanding is a kind of replacement to the php infront of the filename in cron, right?

What is the advantage of including this line into my cron executed php scripts?

merlin
  • 2,130
  • 3
  • 18
  • 38

2 Answers2

1

The main advantage of using a shebang instead of explicitly invoking the interpreter is that you don't have to remember which interpreter to use for any given script (which itself is more useful if you use nice filenames without file extensions on them as is traditional for UNIX executables).

Since cronjobs are hardcoded, there isn't much benefit in your particular case. It would let you rewrite the script in a different language without having to edit the cronjob itself.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
0

The shebang is used to let Linux know what interpreter is used. So when you make that script an executable with chmod +x file and you execute the script directly with ./file than Linux knows how to execute it.

When executing the script with php file.php linux tries to search for the binary in the PATH.

oscarteg
  • 189
  • 1
  • 8