make a PHP script executable from CLI and include-able? -


consider this:

#!/usr/bin/php <?php class foo {         static function bar () {                 echo "foo->bar\n";         } } if (php_sapi === 'cli') {         foo::bar(); } ?> 

i can execute cli, when include in, say, cgi-run php script, shebang ends in output.

i simple scripts compact: guess put class part in separate "lib"-file , have simple wrapper cli use. i'd keep in 1 place without having worry include paths etc.

is possible without ob_*-wrapping include capture shebang (if possible), or dumb cram of 1 file anyway? alternatives/thoughts/best practices welcome!

edit: i'd put script in path, calling i'd rather not call php file.php. see comment @misplacedme's answer

it's easy.
remove shebang , when run script, run as
php scriptname.php or /path/to/php scriptname.php
instead of
./scriptname.php

running php script.php in current directory, or directory within path. if absolutely have run way, add it. export path=$path:/path/to/php/script/folder(in bash)
mess includes unless you're using full paths within script.
no matter do, you'll have use full paths somewhere.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -