News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sean Coates' Blog:
Use `env`
May 21, 2012 @ 11:58:34

Sean Coates has posted a reminder for PHP developers (and really anyone executing command-line scripts) to use "env" instead of hard-coding the path to the PHP interpreter.

These [support] scripts often run PHP in Gimme Bar land, and we make extensive use of the shebang syntax that uses common Unix practice of putting #!/path/to/interpreter at the beginning of our command-line code. Clearly, this is nothing special -lots of people do exactly this same thing with PHP scripts. One thing I have noticed, though, is that many developers of PHP scripts are not aware of the common Unix(y) environment helper, env.

The "env" alias makes use of your currently defined include path to track down a PHP binary to use to execute the script. Since there's only a "best practices" approach to places to put PHP on a server, the "env" usage makes your script more portable and it's one less thing to remember to change.

If you distribute a PHP application that has command-line scripts and shebang lines, I encourage you to adopt the practice of making your shebang line "#!/usr/bin/env php". Note that this doesn't just apply to PHP of course, but I've seen a definite lack of env in the PHP world.
0 comments voice your opinion now!
env environment include path find executable shebang


blog comments powered by Disqus

Similar Posts

KillerPHP.com: Two New Video Tutorials Posted

Geshan Manandhar: Getting started with PHP (LEMP) on Vagrant, the easiest way

Aaron Pollock: Setting up a PHP development environment on a VPS

PHPFreak.dk: The quest for the holy... development environment?!

PHPFive.net: Creating a dynamic Google sitemap using the PHP5 SimpleXML extension


Community Events





Don't see your event here?
Let us know!


voicesoftheelephpant application symfony opinion tool podcast release install composer community language framework security version package interview introduction library laravel series

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework