PHP命令行模式基本介绍
首先要保证php在cli模式下可用,php –v会返回PHP的版本号。
[gaojian3@log001 ~]$ php -v
PHP 5.2.14 (cli) (built: Aug 31 2012 15:03:20)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
一、命令行自定义变量
在命令行里输入程序参数来更改其运行方式是很常见的做法。你也可以对CLI程序这样做。PHP CLI带有两个特殊的变量,专门用来达到这个目的:
1、$argv变量,它通过命令行把传递给PHP脚本的参数保存为单独的数组元素(v:value)
2、$argc变量,它用来保存$argv数组里元素的个数(c : count)
test.php脚本:
<?php
print_r ($argv);
var_dump ($argc);
?>
[gaojian3@log001 ~]$ php /usr/home/gaojian3/test.php 56787 98989 0000
Array
(
[0] => /usr/home/gaojian3/test.php
[1] => 56787
[2] => 98989
[3] => 0000
)
int(4)
正如你可以从输出的结果看到的,传递给test.php的值会自动地作为数组元素出现在$argv里。要注意的是,$argv的第一个自变量总是脚本自己的名称。使用:采用 $argv[3] 这种形式来获取参数。
二、命令行变量
除了用命令行传递PHP脚本参数,还可以传递PHP CLI参数以更改其工作方式。
[gaojian3@log001 ~]$ man php
NAME
php - PHP Command Line Interface ’CLI’ SYNOPSIS
php [options] [ -f ] file [[--] args...] php [options] -r code [[--] args...] php [options] [-B code] -R code [-E code] [[--] args...] php [options] [-B code] -F file [-E code] [[--] args...] php [options] -- [ args...] php [options] -a OPTIONS
--interactive
-a Run PHP interactively. This lets you enter snippets of PHP code that directly get executed. When readline support is
enabled you can edit the lines and also have history support. --php-ini path|file
-c path|file Look for php.ini file in the directory path or use the specified file --no-php-ini
-n No php.ini file will be used --define foo[=bar]
-d foo[=bar] Define INI entry foo with value bar -e Generate extended information for debugger/profiler --file file
-f file Parse and execute file --global name
-g name Make variable name global in script. --help
-h This help --hide-args
-H Hide script name (file) and parameters (args...) from external tools. For example you may want to use this when a php
script is started as a daemon and the command line contains sensitive data such as passwords. --info
-i PHP information and configuration --syntax-check
-l Syntax check only (lint) --modules
-m Show compiled in modules --run code
-r code Run PHP code without using script tags ’<?..?>’ --process-begin code
-B code Run PHP code before processing input lines --process-code code
-R code Run PHP code for every input line --process-file file --modules
-m Show compiled in modules --run code
-r code Run PHP code without using script tags ’<?..?>’ --process-begin code
-B code Run PHP code before processing input lines --process-code code
-R code Run PHP code for every input line --process-file file
-F file Parse and execute file for every input line --process-end code
-E code Run PHP code after processing all input lines --syntax-highlight
-s Display colour syntax highlighted source --version
-v Version number --stripped
-w Display source with stripped comments and whitespace --zend-extension file
-z file Load Zend extension file args... Arguments passed to script. Use ’--’ args when first argument starts with ’-’ or script is read from stdin --rfunction name
--rf name Shows information about function name --rclass name
--rc name Shows information about class name --rextension name
--re name Shows information about extension name
实际上,本文一开始参数传递部分只是php cli模式下的一小部分,之所以单独摘出来,是因为参数传递最常用,也是平时用得最多的部分。
最好玩的部分是php –a,php的交互模式,之前没发现,现在发现真心很好用。其余的还有好多,大家都试下。
[gaojian3@log001 ~]$ php -a
Interactive mode enabled <?php
echo 97678%32;
14
echo "my code";
my code
PHP命令行模式基本介绍的更多相关文章
- 好压(HaoZip)的命令行模式用法介绍
好压压缩软件,又叫“2345好压”,是一款国产的优秀压缩软件,目前是免费的,据官网介绍,该软件永久免费.官网地址:http://haozip.2345.com/ 本文主要对该软件的命令行模式用法进行介 ...
- WinRAR的命令行模式用法介绍
因工作中要对数据打包,顺便研究了下WinRAR的命令行模式,自己写了些例子,基本用法如下: 测试压缩文件准备:文件夹test_data,内部包含子文件夹,分别存放了一些*.log和*.txt文件. 测 ...
- 命令行模式下 MYSQL导入导出.sql文件的方法
一.MYSQL的命令行模式的设置:桌面->我的电脑->属性->环境变量->新建->PATH=“:path\mysql\bin;”其中path为MYSQL的安装路径.二.简 ...
- 《Practical Vim》第五章:命令行模式
前言 出于历史原因,命令行模式又叫 Ex 模式,它具有的功能有: 读写文件:比如 :edit, :write 等等 创建标签页或者窗口:比如 :tabnew :split 操作缓存区,比如: bnex ...
- Linux(CentOS 7)命令行模式安装VMware Tools 详解
本篇文章主要介绍了如何在Linux(CentOS 7)命令行模式安装VMware Tools,具有一定的参考价值,感兴趣的小伙伴们可以参考一下. 本例中为在Linux(以CentOS 7为例)安装VM ...
- jmeter命令行模式运行,实时获取压测结果
jmeter命令行模式运行,实时获取压测结果 jmeter很小,很快,使用方便,可以在界面运行,可以命令行运行.简单介绍下命令行运行的方式: sh jmeter.sh -n -t my-script. ...
- PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)
源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...
- Jmeter使用非 GUI 模式,即命令行模式运行实例讲
转载:http://www.cnblogs.com/leeboke/p/5238269.html 参考资料:https://girliemangalo.wordpress.com/2009/10/29 ...
- 命令行模式运行jmeter,主从方式运行jmeter
jmeter很小,很快,使用方便,可以在界面运行,可以命令行运行.简单介绍下命令行运行的方式: sh jmeter.sh -n -t my-script.jmx -R 10.6.5.31,10.6.5 ...
随机推荐
- 关于Cygwin——包管理、替换默认终端、同MSYS的比较
(搬运自我在SegmentFault的博客) Cygwin 是一个用于 Windows 的类 UNIX shell 环境. 它由两个组件组成:一个 UNIX API 库,它模拟 UNIX 操作系统提供 ...
- C#模糊查询绑定datagridview
private CollectionViewSource wgdData = new CollectionViewSource(); private DataTable Ds_wgd { get { ...
- TreeSet,Comparator
ThreeSet能够对集合中的对象排序,当TreeSet想集合中加入一个对象时,会把它插入到有序的对象序列中. ThreeSet自带了一个排序方法,这个方法规定了一般数据的排序规则,如果用户想要规定自 ...
- hdu 4613 Points<计算几何>
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4613 题意: 判断一个集合中的点能不能由另一个集合中的点,通过平移,旋转,放缩得到~ 思路:先求出集合中的 ...
- KafkaOffsetMonitor使用方法
(1)下载jar包 去网上搜索KafkaOffsetMonitor即可. 我这里共享了我的百度云连接:http://yun.baidu.com/s/1nvGjbDn 如果某一天我这个取消共享了,大家去 ...
- ubuntu中安装Rstdio无法切换中文输入法
安装了RStudio,发现没法切换出中文输入法,搜索了一下 具体参考这里:https://support.rstudio.com/hc/en-us/articles/205605748-Using-R ...
- 路由设置 windows
打印路由信息: route print 如何临时添加电脑内部路由[ route add 网段 mask 子网掩码 网关] 例如:route add 172.18.0.0 mask 255.255.0. ...
- Powershell下设置环境变量
NODE中经常会用到process.env.NODE_ENV来判断当前环境,因为使用的系统是windows,在sublime text下安装terminal插件后,默认启动的时Powershell, ...
- 一次我们网站的web性能优化
1.Google的Web优化最佳实践 利用PageSpeed工具 对我们红酒世界网进行检测时,发现了下面的几个问题 1.Leverage browser caching 1.1.通过web.confi ...
- mysql启动问题access denied for user 'root'@'localhost'(using password:YES)
安装Mysql后利用SQLyogEnt启动是提示“access denied for user 'root'@'localhost'(using password:YES)”,开始我还为是因为是密码问 ...