This has been bugging me slightly.
I know you can do
php foo.php
or
php -f foo.php
Is there no way to just launch a script with the execute bit set
./foo.php
Given the folowing:
#!/usr/bin/php
<?php
exit('hello');
I get “Could not open input file” or ” bad interpreter: No such file or directory” depending on if there’s whitespace after “bin/php”.
The example code you’ve given seems OK and works for me (I added the the closing
?>though)If you can run the file with
/usr/bin/php foo.phpthere’s something weird going on. Just a wild guess, but maybe you text editor leaves a BOM (byte order mark) at the beginning of the file, so that the#!aren’t the very first two bytes in that file. (you can find out by doinghexdump -C foo.php | head)