Search code examples
phpphar

how can a .phar file be executed in command line


I don't understand how a .phar file can be executed in command line in linux. If it can be executed just by entering the filename, it shoudl have been converted to binary.

The usual way of executing a php file would be by entering php filename.php (asking the php interpreter to execute the file) . but in the case of a .phar file the file gets executed automatically even though what it contains is a php application. how this is done?


Solution

  • check the beginning of the file. If it is a script, shell, php, python, whatever script, it has its own interpreter at the very beginning in the syntax of

    #!/bin/interpeter

    and if the file has +x permission, it can be executed as if it was a normal binary executable file.