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 ...
随机推荐
- delphi 单引号在字符串中使用方法
可以看delph的帮助,里面有这个问题详细说明:A character string, also called a string literal or string constant, consist ...
- .Net并行编程
1.什么是线程?线程和进程的区别是什么? 线程是程序执行的最小单元. 区别: 进程是操作系统进行资源处理和分配的最小单位,而一个进程可以包含多个线程,并共享进程的资源. 2.什么是多线程?为什么设计多 ...
- Java当中的I/O的字符流
字符流读写文件时,以字符为基础 I/O当中字符流的核心类 Reader类和Writer类是所有字符流类的父类,同样也是抽象类.FileReader和FileWriter分别是它们的子类. 核心类的核心 ...
- outlook配置
有时打开outlook报错.步骤如下: 一.打开控制面板-邮件-电子邮件账户-新建 二.具体设置如下: 三.点第二步上的“其他设置(M)”.做发送服务器.
- C#.Net 图片处理大全
C# How to: Image filtering by directly manipulating Pixel ARGB values C# How to: Image filtering imp ...
- Java检测文件是否UTF8编码
介绍UTF-8编码规则 UTF-8 编码字符理论上可以最多到 6 个字节长, 然而 16 位 BMP 字符最多只用到 3 字节长. Bigendian UCS-4 字节串的排列顺序是预定的. 字节 0 ...
- linux CentOS 系统下如何将php和mysql命令加入到环境变量中
在Linux CentOS系统上安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行“php -v”命令查看当前php版本信息时时, ...
- MVC4.0 WebApi如何设置api支持namespace
1.自定义HttpControllerSelector /// <summary> /// 设置api支持namespace /// </summary> public cla ...
- SCSF智能客户端学习笔记(一)
什么是智能客户端 要了解智能客户端,首先要认识瘦客户端技术和胖客户端技术各自的优缺点. 对于前者,典型的应用就是使用浏览器,通过输入URL远程访问服务端,并向服务端发送命令,获取服务端的资源,然后在客 ...
- 实体框架 (EF) 入门 => 一、我该用哪个工作流?
入门的参考资料:http://msdn.microsoft.com/zh-cn/data/ee712907 本篇的参考资料:http://msdn.microsoft.com/zh-cn/data/j ...