From ae8dce1d70a51cd35223243d35387fce843c39c6 Mon Sep 17 00:00:00 2001 From: Kris Jordan Date: Sun, 8 Jul 2012 19:45:43 -0400 Subject: [PATCH] Added section on Command Line Interface PHP's command line interface is a simple, powerful way to automate common tasks. New PHP programmers often do not take advantage of PHP's CLI capabilities because they only think of PHP scripts as something that must run in the browser over HTTP. A simple, gentle introduction to running PHP scripts from the command line will help raise awareness that you can accomplish powerful, admin-only tasks through simple PHP scripts without having to craft a UI or open it up to the security issues of the web. --- _includes/command-line-interface.md | 45 +++++++++++++++++++++++++++++ _layouts/default.html | 1 + index.html | 3 ++ 3 files changed, 49 insertions(+) create mode 100644 _includes/command-line-interface.md diff --git a/_includes/command-line-interface.md b/_includes/command-line-interface.md new file mode 100644 index 0000000..1998407 --- /dev/null +++ b/_includes/command-line-interface.md @@ -0,0 +1,45 @@ +# Command Line Interface + +PHP was created primarily to write web applications, but it's also useful for scripting command line interface (CLI) programs, too. Command line PHP programs can help you automate common tasks like testing, deployment, and application administrativia. + +CLI PHP programs are powerful because you can use your app's code directly without having to create and secure a web GUI for it. Just be sure not to put your CLI PHP scripts in your public web root! + +Try running PHP from your command line: + + > php -i + +The `-i` option will print your PHP configuration just like the [`phpinfo`][0] function. There are a number of other useful [command line options][1], too. + +Let's write a simple "Hello, $name" CLI program. To try it out, create a file named `hello.php`, as below. + + php hello.php + Usage: php hello.php [name] + > php hello.php world + Hello, world + +## Built-in, command line web server + +Starting with PHP 5.4, you can develop locally on a PHP-enabled web server without the hassle of installing and configuring a full-fledged web server. To start the server, from your web root: + + > php -S localhost:8000 + + * [Learn about running PHP from the command line][5] + * [Learn about the built-in, command line web server][4] + +[0]: http://php.net/manual/en/function.phpinfo.php +[1]: http://www.php.net/manual/en/features.commandline.options.php +[2]: http://php.net/manual/en/reserved.variables.argc.php +[3]: http://php.net/manual/en/reserved.variables.argv.php +[4]: http://www.php.net/manual/en/features.commandline.webserver.php +[5]: http://php.net/manual/en/features.commandline.php diff --git a/_layouts/default.html b/_layouts/default.html index 4c1db35..071531e 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -39,6 +39,7 @@
  • Password Hashing with Bcrypt
  • Dependency Management
  • Web Application Security
  • +
  • Command Line Interface
  • Popular Frameworks
  • Links & Resources
  • diff --git a/index.html b/index.html index 7d6aec6..9ca5126 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,9 @@ layout: default {% capture security_content %}{% include web-application-security.md %}{% endcapture %} {{ security_content|markdownify }} +{% capture cli_content %}{% include command-line-interface.md %}{% endcapture %} +{{ cli_content|markdownify }} + {% capture frameworks_content %}{% include popular-frameworks.md %}{% endcapture %} {{ frameworks_content|markdownify }}