Making an executable PHP script


Super basic, and I don’t know why I’ve never done this before; a PHP script can be run in a UNIX or Linux (etc) terminal session (etc) just like a BASH script or other standard UNIX shell script:

% cat php_script
#!/usr/bin/env php
<?php
print "Arguments:\n";
print_r($argv);

% chmod 755 php_script

% ./php_script fnord ranger
Arguments:
Array
(
    [0] => ./php_script
    [1] => fnord
    [2] => ranger
)


Comments