Command line arguments for the PHP CLI
Posted June 19th, 2008 in PHP
The PHP command line interface or CLI allows you to run PHP scripts from the command line. It also has a number of flags that can be passed to it which allow you to see which modules are available, do a syntax check on a file, view PHP information etc. This post gives a basic list of the command line arguments available for the PHP CLI and in later posts I will look at some of the options in more detail.
To show all the options that are available, do this:
php --help
This will return a list of all the options available that can be passed to the PHP CLI. The following output comes from a default PHP install on a CentOS 5.0 machine:
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a
-a Run interactively
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-B <begin_code> Run PHP <begin_code> before processing input lines
-R <code> Run PHP <code> for every input line
-F <file> Parse and execute <file> for every input line
-E <end_code> Run PHP <end_code> after processing all input lines
-H Hide any passed arguments from external tools.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
--rf <name> Show information about function <name>.
--rc <name> Show information about class <name>.
--re <name> Show information about extension <name>.
To run a PHP script you would simply call "php" followed by the script name, e.g.:
php myscript.php
To get the PHP version you would do this:
php -v
which will output something along the lines of this:
PHP 5.1.6 (cli) (built: Sep 20 2007 10:16:10) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
That's all for this post. In future posts I will examine some of the other flags in more detail.
Recent posts:
- List installed packages with YUM (Tuesday, December 2nd 2008)
- Monthly Roundup - November 2008 (Monday, December 1st 2008)
- Weekly Roundup - December 1st 2008 (Monday, December 1st 2008)
- Installing subversion on CentOS (Sunday, November 30th 2008)
- GoDaddy 99 cent .com domain coupon code (Saturday, November 29th 2008)
- Find the index of a string within a string with Javascript (Friday, November 28th 2008)
Subscribe to RSS Feed / Email / Bookmark / Share
Use the buttons below to subscribe to my RSS feed to be notified next time something is posted, share this post with others, or subscribe by email and have my posts sent in a daily email.
