当前位置:首页 » 编程语言 » 后台执行php脚本

后台执行php脚本

发布时间: 2025-02-12 17:21:45

❶ Unix/linux中如何直接执行php脚本文件

使用Linux系统搭建完整的PHP环境后,用户常会遇到执行PHP脚本需要使用php myscript.php的方式,感觉较为繁琐。实际上,Linux系统支持直接执行PHP脚本文件。具体操作步骤如下:

首先,编写PHP脚本文件。例如,创建名为test_run.php的文件,内容如下:

Here is some plain text.

Here is the file name:

《?php

echo $argv[0], PHP_EOL;



脚本功能简单,输出当前脚本文件的名称。

接着,通过命令执行脚本:

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

保持脚本内容不变:

《?php

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)”

❷ linux 如何关闭正在执行的php脚本

1. 如果不是后台执行,直接ctrl+c 就终止执行
2. 如果是后台执行
首先执行:sudo ps -ef|grep php

再次执行:sudo kill -9 pid 或者 sudo kill -15 pid

pid 为ps命令查处的进程号。

热点内容
ftp和ssh什么意思 发布:2025-09-17 16:46:18 浏览:494
安卓如何限定应用 发布:2025-09-17 16:35:50 浏览:381
pythoncmd退出命令 发布:2025-09-17 16:16:33 浏览:922
朗动顶配是什么配置 发布:2025-09-17 16:08:35 浏览:441
小孩子学习编程 发布:2025-09-17 16:05:12 浏览:117
vivo手机怎样关闭腾讯视频缓存 发布:2025-09-17 16:03:24 浏览:262
手机内存和存储空间 发布:2025-09-17 15:53:40 浏览:603
小米5怎么升级安卓7 发布:2025-09-17 15:44:14 浏览:916
java培训班一般要多少钱 发布:2025-09-17 15:39:34 浏览:163
脚本挂到宝塔看视频 发布:2025-09-17 15:33:36 浏览:294