Home  >  Article  >  Backend Development  >  Examples of writing shell commands on the php command line

Examples of writing shell commands on the php command line

不言
不言Original
2018-07-26 11:28:222568browse

The content of this article is about writing shell commands on the PHP command line. The content is very detailed. Friends in need can refer to it. I hope it can help you.

php can run like java perl python. Today I discovered that if I had known this earlier, maybe I would not have learned java and python

I learned java back then just to put a program on the server. After running and running, it turns out that php can also be used.

php -h
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] -S <addr>:<port> [-t docroot] [router]
 php [options] -- [args...]
 php [options] -a
 -a    Run as interactive shell
 -c <path>|<file> Look for php.ini file in this directory
 -n    No configuration (ini) files will be used
 -d foo[=bar]  Define INI entry foo with value &#39;bar&#39;
 -e    Generate extended information for debugger/profiler
 -f <file>  Parse and execute <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 <addr>:<port> Run with built-in web server.
 -t <docroot>  Specify document root <docroot> for built-in web server.
 -s    Output HTML syntax highlighted source.
 -v    Version number
 -w    Output 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
 --ini   Show configuration file names
 --rf <name>  Show information about function <name>.
 --rc <name>  Show information about class <name>.
 --re <name>  Show information about extension <name>.
 --rz <name>  Show information about Zend extension <name>.
 --ri <name>  Show configuration for extension <name>.

1. Use the php command line to execute the php script, such as /usr/bin/php test.php

Abbreviationphp test.php

test.php

<?php
for($i=0;$i<10;$i++){
 echo $i;
 echo &#39;\n&#39;;
}
?>

2. Write #!/usr/ on the first line at the beginning of the script bin/php, and then you can set the script to be executable chmod a

Execute for an hour and see if php will hang. I hope that a command line can run forever

#!/usr/bin/php
<?php
for($i=0;$i<10;$i++){
 echo $i;
 echo " java-er.com \n";
}
?>

##3. External incoming parameters

#!/usr/bin/php
<?php
for($i=0;$i<360;$i++){
 echo $i;
 sleep(10);
 echo " java-er.com \n";
}
?>

Related recommendations:

How to use OSS to code in ThinkPHP3 Writing

How to use php code to implement seal cutout (code)

The above is the detailed content of Examples of writing shell commands on the php command line. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn