2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > PHP命令行(CLI模式)的详细介绍

PHP命令行(CLI模式)的详细介绍

时间:2024-07-02 04:27:19

相关推荐

PHP命令行(CLI模式)的详细介绍

后端开发|php教程

PHP命令行

后端开发-php教程

教务管理系统毕业设计源码,vscode xp版下载,ubuntu 汉字不全,tomcat7.0.73,宝塔Sqlite3怎么升级,复制粘贴网页会被反爬虫吗,php 类的斜杠,什么是seo效果推广,天猫网站开源项目组,qx模板是什么意思lzw

本篇文章给大家带来的内容是关于PHP命令行(CLI模式)的详细介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

CLI模式

一元夺宝商城源码下载,vscode 调试命令,ubuntu 群控数量,tomcat 容器接口,sqlite 链接ef,jquery插件 事件,前端框架ssh字典项,爬虫怎么交付,php mysql库,seo自我介绍,简单的静态网站模板 下载,易语言取网页文本模块,资讯文章类织梦模板,js静态页面模板,安卓图书管理系统,在线点餐小程序代码lzw

CLI模式其实就是命令行运行模式,英文全称Command-Line Interface(命令行接口)

php网页登录系统源码,ubuntu怎么清空界面,python爬虫库教学,php斗牛源码百度网盘,seo搜索教程lzw

$ php -hUsage: php [options] [-f] [--] [args...] php [options] -r[--] [args...] php [options] [-B ] -R[-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -S : [-t docroot] [router] php [options] -- [args...] php [options] -a -aRun as interactive shell 以交互shell模式运行 -c | Look for php.ini file in this directory 指定php.ini文件所在的目录 -nNo configuration (ini) files will be used 指定不使用php.ini文件 -d foo[=bar]Define INI entry foo with value ar 定义一个INI实体,key为foo,value为ar -eGenerate extended information for debugger/profiler 为调试和分析生成扩展信息 -f Parse and execute . 解释和执行文件 -hThis help 打印帮助信息 -iPHP information 显示PHP的基本信息 -lSyntax check only (lint) 进行语法检查(lint) -mShow compiled in modules 显示编译到内核的模块 -rRun PHPwithout using script tags 运行PHP代码,不需要使用标签 -B Run PHP before processing input lines 在处理输入之前先执行PHP代码 -RRun PHPfor every input line 对输入的每一行作为PHP代码运行 -F Parse and execute for every input line 对输入的每一行解析和执行 -ERun PHP after processing all input lines 在处理所有输入的行之后执行PHP代码 -HHide any passed arguments from external tools. 隐藏任何来自外部工具传递的参数 -S : Run with built-in web server. 运行内置的web服务器 -tSpecify document root for built-in web server. 指定用于内置web服务器的文档根目录 -sOutput HTML syntax highlighted source. 输出HTML语法高亮的源码 -vVersion number 输出PHP的版本号 -wOutput source with stripped comments and whitespace. 输出去掉注释和空格的源码 -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 显示PHP的配置文件名 --rf Show information about function . 显示关于函数的信息 --rc Show information about class . 显示关于类的信息 --re Show information about extension . 显示关于扩展的信息 --rz Show information about Zend extension . 显示关于Zend扩展的信息 --ri Show configuration for extension . 显示扩展的配置信息

以交互式Shell模式运行PHP

/manual/en/mandline.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的命令行脚本文件

$arg) { echo " {$index} : {$arg}\n";}$ php console.php hello world命令行参数个数: 3命令行参数:: console.php: hello: world

可以看到,第0个参数是我们执行的脚本名称。需要注意的是,如果提供的第一个参数是以-开头的话,需要在前面增加--,以告诉php这后面的参数是提供给我们的脚本的,而不是php执行文件的(php -r var_dump($argv); -- -h)。

另外,在脚本中,我们可以通过php_sapi_name()函数判断是否是在命令行下运行的。

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。