PHP Command Line Interface
References
man php
Run Code
php [options] -r code [[--] args...]--run code,-r codeRun PHP code without using script tags ''- Using parameter
-ryou can directly execute PHP code simply as you would do inside a .php file when using theeval()function.
Run PHP Interactively
php [options] -a--interactive, -aRun PHP interactively.- This lets you enter snippets of PHP code that directly get executed.
- When read‐line support is enabled you can edit the lines and also have history support.
Line Process
php [options] [-B begin_code] -R code [-E end_code] [[--] args...]
php [options] [-B begin_code] -F file [-E end_code] [[--] args...]--process-begin code,-B begin_codeRun PHP begin_code before processing input lines--process-code code,-R codeRun PHP code for every input line--process-file file,-F fileParse and execute file for every input line--process-end code,-E end_codeRun PHP end_code after processing all input lines
HTTP Server
php [options] -S addr:port [-t docroot]--info, -iPHP information and configuration--syntax-check, -lSyntax check only (lint)--modules, -mShow compiled in modules--iniShow configuration file names
Hello world
$ php -r 'echo "hello world\n";'
hello worldRead file
# /usr/home/icehe on server 10.2.3.4
$ php -r "echo file_get_contents('./input1');"
abhishek
divyam
chitransh
naveen
harsh$ cat input1 | php -R 'echo "^".$argn."$\n";'
^abhishek$
^divyam$
^chitransh$
^naveen$
^harsh$With option -B & -E
$ cat input1 | php -B 'echo "begin\n";' -R 'echo "^".$argn."$\n";' -E 'echo "end\n";'
begin
^abhishek$
^divyam$
^chitransh$
^naveen$
^harsh$
end$ cat tmp.php
<?php
echo "^".$argn."$\n";
$ cat input1 | php -F tmp.php
^abhishek$
^divyam$
^chitransh$
^naveen$
^harsh$Server
# /usr/home/icehe on server 10.2.3.4
$ php -S 0.0.0.0:30233 -t .
PHP 7.1.20 Development Server started at Wed Dec 5 17:54:11 2018
Listening on http://0.0.0.0:30233
Document root is /usr/home/icehe
Press Ctrl-C to quit.Read from server
$ curl 10.77.120.249:30233/input1
abhishek
divyam
chitransh
naveen
harsh
# Download
$ curl -LO 10.2.3.4:30233/input1INI
$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/bz2.ini,
/etc/php.d/calendar.ini,
/etc/php.d/ctype.ini,
……Modules
$ php -m
[PHP Modules]
bz2
ctype
……
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcacheInformation
$ php -i
# same as code `phpinfo()`