详解php命令行写shell实例
发布: 来源: PHP粉丝网 添加日期:2022-07-26 12:45:52 浏览: 评论:0
php 可以像java perl python 那样运行,今天发现如果我早早知道这个,或许我不会去学习java 和 python,当年学java不过为了一个程序放在服务器上,不停的跑啊跑,原来 php 也可以。
- php -h
- Usage: 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-a Run as interactive shell-c| Look for php.ini file in this directory -n No configuration (ini) files will be used-d foo[=bar] Define INI entry foo with value 'bar'-e Generate extended information for debugger/profiler-fParse and execute . -h This help-i PHP information-l Syntax check only (lint)-m Show compiled in modules-rRun PHPwithout using script tags-BRun PHP before processing input lines -RRun PHPfor every input line-FParse and execute for every input line -ERun PHP after processing all input lines -H Hide any passed arguments from external tools.-S: Run with built-in web server. -tSpecify document root for built-in web server. -s Output HTML syntax highlighted source.-v Version number-w Output source with stripped comments and whitespace.-zLoad Zend extension . args... Arguments passed to script. Use -- args when first argumentstarts with - or script is read from stdin--ini Show configuration file names--rfShow information about function . --rcShow information about class . --reShow information about extension . --rzShow information about Zend extension . --riShow configuration for extension .
1.用php命令行的方式执行php脚本,例如/usr/bin/php test.php
缩写 php test.php
test.php
for($i=0;$i<10;$i++){echo $i;echo '\n';}?>
2.脚本开头第一行写上#!/usr/bin/php,然后可以把脚本设为可执行 chmod a+x test.php,之后就可以用命令行的方式直接执行脚本了,例如./test.php
#!/usr/bin/phpfor($i=0;$i<10;$i++){echo $i;echo " java-er.com \n";}?>
执行一小时,看看php会不会挂,我希望一个命令行可以跑到天荒地老
#!/usr/bin/phpfor($i=0;$i<360;$i++){echo $i;sleep(10);echo " java-er.com \n";}?>

3. 外部传入参数
#!/usr/bin/phpvar_dump($argc); //返回参数总个数var_dump($argv);exit;?>./test.phpint(1)array(1) {[0]=>string(10) "./test.php"}./test.php a java phpint(4)array(4) {[0]=>string(10) "./test.php"[1]=>string(1) "a"[2]=>string(4) "java"[3]=>string(3) "php"}
Tags: php命令行 shell
- 上一篇:教你使用mixphp打造多进程异步邮件发送
- 下一篇:最后一页
相关文章
- ·强制PHP命令行脚本单进程运行的方法(2020-11-15)
- ·php命令行(cli)下执行PHP脚本文件的相对路径的问题解决方法(2021-05-27)
- ·PHP的命令行命令使用指南(2021-06-16)
- ·php命令行(cli)模式下报require 加载路径错误的解决方法(2021-06-27)
- ·基于命令行执行带参数的php脚本并取得参数的方法(2021-07-07)
- ·php命令行写shell实例详解(2021-10-19)
- ·php根据命令行参数生成配置文件详解(2021-11-12)
- ·php命令行模式代码实例详解(2022-04-13)
- ·从后台到webshell的一点思路(2014-03-07)
- ·shell 脚本检查某目录下php文件语法(2014-07-15)
- ·PHP/Shell大文件数据统计并且排序(2014-07-21)
- ·php webshell扫描后门木马实例程序(2014-08-22)
- ·php webshell下直接反弹shell的例子(2018-10-13)
- ·PHP最短webshell的一些理解(2018-10-15)
- ·实例:实现自动清除日期目录shell脚本(2018-10-26)
- ·php使用exec shell命令注入的方法讲解(2020-06-18)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)
