最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Unix/Linux 下直接执行 PHP 脚本文件
时间:2016-03-03 编辑:简简单单 来源:一聚教程网
由于我们的服务器都是使用的 Linux 系统,并且都有搭建完整的 PHP 环境,所以有时候我会用 PHP 写一些执行自动化任务的脚本,但是每次执行这个 PHP 脚本都需要使用 php myscript.php 的方式,稍微有点儿??隆F涫担?强梢灾苯又葱 PHP 脚本文件的。
编写你的脚本文件
这里我们编写一个名字为 test_run.php 的文件,文件的内容如下:
Here is some plain text.
Here is the file name:
echo $argv[0], PHP_EOL;
?>
脚本内容很简单,就是把当前脚本文件的名称打印出来。
然后,我们使用 PHP 命令执行一下这个脚本:
yuanyu@ymac:phpworkspace $ php test_run.php hello
Here is some plain text.
Here is the file name:
test_run.php
yuanyu@ymac:phpworkspace $
给脚本文件增加头信息,并且设置权限
然后,在这个文件的第一行写上 php 命令的全路径,前面是一个 #!:
#!/usr/bin/php
Here is some plain text.
Here is the file name:
echo $argv[0], PHP_EOL;
?>
然后给这个文件赋予可执行的权限:
yuanyu@ymac:phpworkspace $ chmod u+x ./test_run.php
接下来就可以直接执行这个脚本了:
yuanyu@ymac:phpworkspace $ ./test_run.php
Here is some plain text.
Here is the file name:
./test_run.php
yuanyu@ymac:phpworkspace $
这种方式在 PHP 官方文档中也是有说的,请参考:
http://php.net/manual/en/features.commandline.usage.php
文档中的
“Example #2 Script intended to be run from command line (script.php)”
-
下一个: win7系统关闭win10升级提示的教程
相关文章
- 在Linux系统通过命令行执行php文件传参方法 04-20
- Linux文件句柄数导致php-cgi假死问题解决教程 09-24
- linux中php.ini文件位置查看命令 07-13
- linux防止php 伪造本地文件解决方法 11-04
- win11内核隔离和内存完整性介绍 10-31
- win10全屏缩放设置教程 10-31