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 ...
随机推荐
- 【easyui】—easyui教你编写一个前台的架子
以前做项目都是在别人搭建好的环境下直接编写单独的页面,也没有处理过怎么搭建一个框架.看到别人的布局都挺好的,自己也想做一个走一下流程. 嘿,刚开始时看着别人写的代码,去找怎么写. 这是我自己的想法,使 ...
- tcp,第一个例子,客户端,服务端
1.客户端 package cd.itcast.xieyi; import java.io.IOException; import java.io.OutputStream; import java. ...
- [.ashx檔?泛型处理例程?]基础入门#3....ADO.NET 与 将DB里面的二进制图片还原
原文出處 http://www.dotblogs.com.tw/mis2000lab/archive/2013/08/20/ashx_beginner_03_db_picture_show.aspx ...
- 在EF的code frist下写稳健的权限管理系统:开篇(一)
环境:EF6.0.0.0+Autofac3.5.0.0+MVC4.0+pure6.0+Jquery IDE:vs2012,数据库:vs2008r2 搭建环境如下: 我给它取名字为cactus:仙人球, ...
- oracle 查询今天哪个表增加的数据多
一.创建一个表 create table A( TABLE_NAME VARCHAR2(200), COUNT_NUM NUMBER) 二.创建一个存储过程create or replace ...
- Android JNI如何调用第三方库
http://www.2cto.com/kf/201504/388764.html Android JNI找不到第三方库的解决方案 cannot load library 最近做一个jni项目,拿到的 ...
- centos6 自启动任务
tag: init upstart centos6.x 自启动 initctl event CentOS6开始转用Upstart代替以往的init.d/rcX.d的线性启动方式.upstart的概念就 ...
- [译]AMQP 0-9-1 Quick Reference : basic
Basic basic.ack(delivery-tag delivery-tag, bit multiple)Support: fullAcknowledge one or more message ...
- 38.基于FPGA的FIR设计二
利用fdatool工具生成的滤波器系数与用代码生成的系数不一致,在网上查询得知,fdatool生成的滤波器系数是有符号小数,而且是浮点型,而代码生成的滤波器系数是定点型有符号数,故不一样. 浮点型数据 ...
- mysql 5.7 64位 解压版安装
64位操作系统最好安装64位的mysql数据库,充分利用内存的寻址能力,对于windows而言,mysql官网只提供了32位的MSI安装程序,因为在windows下安装64位的mysql,选择解压版安 ...