国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP命令行(CLI模式)的詳細介紹

2020-03-22 19:30:06
字體:
來源:轉載
供稿:網友
本篇文章給大家帶來的內容是關于html' target='_blank'>PHP命令行(CLI模式)的詳細介紹,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。

CLI模式

CLI模式其實就是命令行運行模式,英文全稱Command-Line Interface(命令行接口)

$ php -hUsage: 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 以交互shell模式運行 -c path | file Look for php.ini file in this directory 指定php.ini文件所在的目錄 -n No configuration (ini) files will be used 指定不使用php.ini文件 -d foo[=bar] Define INI entry foo with value bar  定義一個INI實體,key為foo,value為 bar  -e Generate extended information for debugger/profiler 為調試和分析生成擴展信息 -f file Parse and execute file . 解釋和執行文件 file  -h This help 打印幫助信息 -i PHP information 顯示PHP的基本信息 -l Syntax check only (lint) 進行語法檢查(lint) -m Show compiled in modules 顯示編譯到內核的模塊 -r code Run PHP code without using script tags ?..?  運行PHP代碼 code ,不需要使用標簽 ?..?  -B begin_code Run PHP begin_code before processing input lines 在處理輸入之前先執行PHP代碼 begin_code  -R code Run PHP code for every input line 對輸入的每一行作為PHP代碼 code 運行 -F file Parse and execute file for every input line 對輸入的每一行解析和執行 file  -E end_code Run PHP end_code after processing all input lines 在處理所有輸入的行之后執行PHP代碼 end_code  -H Hide any passed arguments from external tools. 隱藏任何來自外部工具傳遞的參數 -S addr : port Run with built-in web server. 運行內置的web服務器 -t docroot Specify document root docroot for built-in web server. 指定用于內置web服務器的文檔根目錄 docroot  -s Output HTML syntax highlighted source. 輸出HTML語法高亮的源碼 -v Version number 輸出PHP的版本號 -w Output source with stripped comments and whitespace. 輸出去掉注釋和空格的源碼 -z file Load Zend extension file . 載入Zend擴展文件 file  args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin 傳遞給要運行的腳本的參數。當第一個參數以 - 開始或者是腳本是從標準輸入讀取的時候,使用 -- 參數 --ini Show configuration file names 顯示PHP的配置文件名 --rf name Show information about function name . 顯示關于函數 name 的信息 --rc name Show information about class name . 顯示關于類 name 的信息 --re name Show information about extension name . 顯示關于擴展 name 的信息 --rz name Show information about Zend extension name . 顯示關于Zend擴展 name 的信息 --ri name Show configuration for extension name . 顯示擴展 name 的配置信息

以交互式Shell模式運行PHP

http://php.net/manual/en/features.commandline.interactive.php
The interactive shell stores your history which can be accessed using the up and down keys. The history is saved in the ~/.php_history file.
交互shell模式保存輸入的歷史命令,可以使用上下鍵訪問到。歷史被保存在~/.php_history文件。

$ php -aInteractive shellphp echo 5+8;php function addTwo($n)php {php { return $n + 2;php { }php var_dump(addtwo(2));int(4)

查找相關類、擴展或者函數的信息

通常,我們可以使用php --info命令或者在在web服務器上的php程序中使用函數phpinfo()顯示php的信息,然后再查找相關類、擴展或者函數的信息,這樣做實在是麻煩了一些。

$ php --info | grep redisredisRegistered save handlers = files user redisThis program is free software; you can redistribute it and/or modify

語法檢查

只需要檢查php腳本是否存在語法錯誤,而不需要執行它,比如在一些編輯器或者IDE中檢查PHP文件是否存在語法錯誤。

使用-l(--syntax-check)可以只對PHP文件進行語法檢查。

$ php -l index.phpNo syntax errors detected in index.php

假如index.php中存在語法錯誤。

$ php -l index.phpPHP Parse error: syntax error, unexpected echo (T_ECHO) in index.php on line 3Parse error: syntax error, unexpected echo (T_ECHO) in index.php on line 3Errors parsing index.php

命令行腳本

$argc 包含了 $argv數組包含元素的數目
$argv 是一個數組,包含了提供的參數,第一個參數總是腳本文件名稱
console.php的命令行腳本文件

 ?phpecho 命令行參數個數: . $argc . /n echo 命令行參數:/n foreach ($argv as $index = $arg) { echo {$index} : {$arg}/n 
: hello: world

可以看到,第0個參數是我們執行的腳本名稱。需要注意的是,如果提供的第一個參數是以-開頭的話,需要在前面增加--,以告訴php這后面的參數是提供給我們的腳本的,而不是php執行文件的(php -r var_dump($argv); -- -h)。
另外,在腳本中,我們可以通過php_sapi_name()函數判斷是否是在命令行下運行的。

$ php -r echo php_sapi_name(), PHP_EOL; cli

以上就是PHP命令行(CLI模式)的詳細介紹的詳細內容,PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肇东市| 花垣县| 宜川县| 嘉峪关市| 石城县| 龙海市| 文登市| 湖州市| 原平市| 崇左市| 陆良县| 高碑店市| 虹口区| 霍城县| 广东省| 扬州市| 神池县| 喜德县| 特克斯县| 荥经县| 裕民县| 鄂尔多斯市| 米泉市| 平利县| 福鼎市| 灵山县| 溆浦县| 璧山县| 和政县| 亚东县| 喀什市| 内丘县| 玉田县| 康乐县| 秭归县| 白城市| 峨眉山市| 科尔| 离岛区| 山阳县| 德阳市|