Common PHP Command‑Line Options and Script Development Guide

This article introduces the most frequently used PHP command‑line switches, explains how to retrieve module, version, configuration and help information, and demonstrates basic CLI script development with $argv and $argc, including a complete example and its output.

php Courses
php Courses
php Courses
Common PHP Command‑Line Options and Script Development Guide

This guide lists essential PHP command‑line options and their purposes.

1. php -m – displays compiled modules.

2. php -v – shows the PHP version.

3. php --ini – shows the loaded configuration file.

4. php -h – displays available command‑line commands.

5. php --info – shows detailed information about classes, functions, and extensions, similar to the output of phpinfo() in a web server.

6. php --rf <name> – shows information about a specific function.

7. php --rc <name> – shows information about a specific class.

8. php --re <name> – shows information about a specific extension.

9. php --ri <name> – displays configuration information for the given extension.

10. php --rz <name> – displays information about a Zend extension.

The article also explains basic command‑line script development in PHP:

$argv is an array containing the script name and all passed arguments.

$argc holds the number of arguments.

Example script (index.php):

<?php
echo 'Command line argument count: ' . $argc . "
";
echo "Command line arguments:
";
foreach ($argv as $index => $arg) {
    echo "    {$index} : {$arg}
";
}

Running the script from the command line: php index.php 1 2 3 The output shows the argument count and lists each argument with its index.

For more details, click the “Read Original” link at the end of the article.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLIPHPcommand-lineScripting
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.