全面總結php在cli命令列模式下的使用

2021-05-24 08:24:58 字數 4252 閱讀 9519

php cli命令列模式是win下的乙個shell,不需要apache的支援就能執行php指令碼的指令碼,並且是持續執行的。這些特點很容易利用來快速測試php指令碼。今天有人問到,我再次做乙個全面總結。本文主要介紹了在php的cli模式,即命令列模式下的使用入門,以及一些技巧和需要注意的問題。

在你的命令列介面下,進入安裝目錄,執行以下命令d:/dev/php5>php -help,

你就能看到你的輸出了。其中打黃底的文字是你需要著重了解的功能。

usage: php [options] [-f]

[--] [args...]

php [options] -r[--] [args...]直接執行**

php [options] [-b

] -r[-e

] [--]

[args...]

php [options] [-b

] -f

[-e

] [--]

[args...]

php [options] -- [args...]

php [options] -a

-a               run interactively互動執行

-c |

look for php.ini file in this directory在這個目錄尋

找php.ini檔案

-n               no php.ini file will be used不使用php.ini檔案

-d foo[=bar]     define ini entry foo with value 'bar'

-e               generate extended information for debugger/profiler

-f

parse and execute

. -h               this help

-i               php information類似phpinfo()函式

-l               syntax check only (lint)

-m               show compiled in modules

-rrun phpwithout using script tags

直接執行**。雙引號包圍,分號結尾

-b

run php

before processing input lines

-rrun phpfor every input line

-f

parse and execute

for every input line

-e

run php

after processing all input lines

-h               hide any passed arguments from external tools.

-s               display colour syntax highlighted source.高亮顯示**

-v               version number版本資訊

-w               display source with stripped comments andwhitespace.去除注釋和空白後顯示源**

-z

load zend extension

.載入zend擴充套件

args...          arguments passed to script. use -- args when first

argument

starts with - or script is read from stdin

--ini            show configuration file names

--rf

show information about function

.顯示乙個函式的原型描述

--rc

show information about class

.顯示類的描述

--re

show information about extension

.顯示對擴充套件的描述

--ri

show configuration for extension

.顯示擴充套件配置資訊

①在命令列介面中處理輸入輸出

**: if(!defined("stdin"))

//php5.2裡面stdin已經定義了

echo "hello! what is your name (enter below):/n";

$strname = fread(stdin, 80);

echo 'hello ',$strname, "/n";

?>

②在php的cli模式下直接執行**:

php -r "echo 3*4";

③檢視函式原型

>php --rf print_r

輸出 function [

function print_r ]

}

④顯示php擴充套件的描述資訊

>php --re exif

輸出 extension [

extension #30 exif version 1.4 $id: exif.c,v

1.173.2.5.

2.25 2008/03/12 17:33:14 iliaa exp $ ]

- ini

entry [ exif.decode_unicode_motorola

] current = 'ucs-2be'

}

entry [ exif.decode_unicode_intel

] current = 'ucs-2le'

}

entry [ exif.encode_jis

] current = ''

}

entry [ exif.decode_jis_motorola

] current = 'jis'

}

entry [ exif.decode_jis_intel

] current = 'jis'

}

}

- constants [1]

}

- functions

}

function [

function read_exif_data ]

}

function [

function exif_tagname ]

}

function [

function exif_thumbnail ]

}

function [

function exif_imagetype ]

}

}

}

dependency [ mbstring (required) ]

⑤在命令列下,php讀取輸入引數

echo $_server["argv"][1]."/n";

可以看到,引數是儲存在argv這個陣列裡的

⑥把命令列下的輸出儲存到檔案裡

這個只要使用dos的》重定向符號就可以了。

⑦連續讀寫檔案操作。

php命令列模式 cli 的使用 總結

hp cli模式的優勢及使用場合 1.完全支援多執行緒 php本身是單執行緒指令碼語言 php cli是php多執行緒應用,雖然大家都普遍認為php沒有多執行緒 curl屬於模擬多執行緒而不是真實的 但是在php cli模式下的php徹底的是屬於多執行緒。這個時候php屬於linux的乙個守護程序 ...

Flask內建命令列工具 CLI

unix bash linux,mac,etc.flask run windows cmd flask run windows powershell flask run 設定src為當前工作目錄,並匯入hello 匯入hello.web 執行開發伺服器。不消說,不要在生產環境使用 開啟乙個互動式的p...

Flask內建命令列工具 CLI

unix bash linux,mac,etc.flask run windows cmd flask run windows powershell flask run 設定src為當前工作目錄,並匯入hello 匯入hello.web 執行開發伺服器。不消說,不要在生產環境使用 開啟乙個互動式的p...