PHP ʖ²ἯTH º󍋼/A ¾¡¹ܠCGI SAPI ̡¹©Kȡϻ HTTP ͷЅϢµķ½·¨£¬µ«Ԛ CLI SAPI ֐²¢²»´攚 ˆµķ½·¨Ҕ¿ªƴ HTTP ͷЅϢµĊ䳶¡£ CLI SAPI ǿֆ¸􁋠php.ini ֐µĄ³Щɨփ£¬ҲΪբЩɨփԚ͢¿ǻ·¾³ςʇûӐҢҥµġ£ ɨփѡϮ CLI SAPI Ĭȏֵ ±¸ע html_errors FALSE implicit_flush TRUE max_execution_time 0 £¨ΞϞֵ£© register_argc_argv TRUE ³£û³Ƽ/TH è ʶ STDIN $stdin = fopen('php://stdin', 'r'); STDOUT $stdout = fopen('php://stdout', 'w'); STDERR $stderr = fopen('php://stderr', 'w'); php -r 'fwrite(STDERR, "stderr\n");' CLI SAPI ²»»Ὣµ±ǰĿ¼¸ĎªґԋАµĽű¾˹ԚµĄ¿¼¡£ Ҕς·¶=ϔʾK±¾ģ¿铫 CGI SAPI ģ¿閮¼䵄²»ͬ£º ?php /* Our simple test application named test.php*/ echo getcwd(), "\n";? $pwd /tmp $php-cgi -f another_directory/test.php /tmp/another_directory ʹӃ CLI SAPI ģʽ£¬Βǵõ½£º $pwd /tmp $php -q another_directory/test.php /tmp Usage: php [options] [-f] file [args...] php [options] -r code [args...] php [options] [-- args...] -s Display colour syntax highlighted source. -w Display source with stripped comments and whitespace. -f file Parse file. -v Version number -c path | file Look for php.ini file in this directory -a Run interactively -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -z file Load Zend extension file. -l Syntax check only (lint) -m Show compiled in modules -i PHP information -r code Run PHP code without using script tags?..? -h This help args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin ȃ PHP ԋАָ¶¨΄¼þ¡£ php my_script.php php -f my_script.php php -r 'print_r(get_defined_constants());' ԚʹӃբ֖·½·¨ʱ£¬ǫĺעҢ͢¿DZ䁿µČ洺¼°ҽºŵĊ¹Ӄ¡£ $some_application | some_filter | php | sort -u final_output.txt #!/usr/bin/php ?php var_dump($argv);? $chmod 755 test $./test -h -- foo array(4) {[0]= string(6) "./test" [1]= string(2) "-h" [2]= string(2) "--" [3]= string(3) "foo"} ѡϮû³Ƽ/TH è ʶ -s ϔʾӐӯ·¨¸߁I«²ʵĔ´΄¼þ¡£ -w -f -v $php -v PHP 4.3.0-dev (cli), Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies -c $php -c /custom/directory/ my_script.php $php -c /custom/directory/custom-file.ini my_script.php -a ½»»¥µؔːРPHP¡£ -d Ӄ¸òΊÿ‰’”—ԐЉ薃 php.ini ΄¼þ֐ɨփ±䁿µĖµ£¬Ƥӯ·¨Ϊ£º -d configuration_directive[=value] ·¶=£º # Ommiting the value part will set the given configuration directive to "1" $php -d max_execution_time -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(1) "1" # Passing an empty value part will set the configuration directive to ""php -d max_execution_time= -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(0)"" # The configuration directive will be set to anything passed after the '=' character $php -d max_execution_time=20 -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(2) "20" $php -d max_execution_time=doesntmakesense -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(15) "doesntmakesense" -e -z -l -m $php -m [PHP Modules] xml tokenizer standard session posix pcre overload mysql mbstring ctype [Zend Modules] -i -r ϔʾӯ·¨½⎶´펳µķ¶= $php -r "$foo = get_defined_constants();" Command line code(1): Parse error - parse error, unexpected '=' $php -r "= get_defined_constants();" $php -r '$foo = get_defined_constants(); var_dump($foo);' array(370) {["E_ERROR"]= int(1) ["E_WARNING"]= int(2) ["E_PARSE"]= int(4) ["E_NOTICE"]= int(8) ["E_CORE_ERROR"]= [...] -h =ד 23-1. ʔͼҔünА·½ʽԋАµĠPHP ½ű¾£¨script.php£© #!/usr/bin/php ?php if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {? This is a command line PHP script with one option. Usage: ?php echo $argv[0];? option option can be some word you would like to print out. With the --help, -help, -h, or -? options, you can get this help. ?php} else {echo $argv[1];}? @c:\php\cli\php.exe script.php %1 %2 %3 %4 ǫ²ΔĠReadline )չģ¿鵄Ӑ¹؎ĵµ£¬Ҕ»񈡸þ µ„º¯ʽµĐŏ¢¡£բЩº¯ʽ¿ɒ԰ĺͪɆĺµĠPHP ünАӦӃ³̐򡣊 º󍋼/A ưµ㼯A ±»°²ȫģʽϞֆ»򆁱εĺ¯ʽ ɏһ¼¶ º¯ʽ²ο¼