当前位置:网站首页>PHP的exec函数
PHP的exec函数
2022-06-29 02:23:00 【hello php】
代码如下:
<?php
$out = ['a'=>'apple','b'=>'banana','c'=>'cat','d'=>'dog'];
$shell_return=null;
$v = exec('netstat -tnlp',$out,$shell_return);
print_r($out);
var_dump($shell_return);
var_dump($v);
执行后的输出如下:
Array
(
[a] => apple
[b] => banana
[c] => cat
[d] => dog
[0] => Active Internet connections (only servers)
[1] => Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
[2] => tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
[3] => tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 7311/dnsmasq
[4] => tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6987/sshd
[5] => tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 6978/cupsd
[6] => tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 16181/sshd: [email protected]
[7] => tcp6 0 0 :::3306 :::* LISTEN 7361/mysqld
[8] => tcp6 0 0 :::111 :::* LISTEN 1/systemd
[9] => tcp6 0 0 :::8080 :::* LISTEN 7689/httpd
[10] => tcp6 0 0 :::80 :::* LISTEN 7689/httpd
[11] => tcp6 0 0 :::22 :::* LISTEN 6987/sshd
[12] => tcp6 0 0 ::1:631 :::* LISTEN 6978/cupsd
[13] => tcp6 0 0 ::1:6011 :::* LISTEN 16181/sshd: [email protected]
[14] => tcp6 0 0 :::8000 :::* LISTEN 7689/httpd
)
int(0)
string(90) "tcp6 0 0 :::8000 :::* LISTEN 7689/httpd"
结论:
exec($shell, $output, $shell_return)
- $shell: shell命令, 如: 'netstat -tnlp'
- $output: 执行shell命令后的输出结果, 注意: 如果$output之前有值, 在将输出的数据追加到原来的数据之后
- $shell_return: shell命令的执行结果, 如果执行成功,返回0, 失败为其他值
- exec函数执行后的返回值: 返回$output数组的最后一条数据
边栏推荐
- Why install an SSL certificate on a web site?
- 跨境资讯站
- 学习太极创客 — MQTT 第二章(九)本章测试
- Secondary encapsulation of storage (sessionstorage/localstorage) using TS
- Kubernetes: container resource requirements and constraints (constraints)
- [apprendre la programmation FPGA - 49 à partir de zéro]: vision - Comment la puce a - t - elle été conçue?
- Eliminate the hover effect when the button is disabled
- 瀑布型项目管理最常用的10个小工具,可以自由搭建使用
- 【Redis】List类型
- String substitution
猜你喜欢

Talk about the copyonwritearraylist of JUC

学习太极创客 — MQTT 第二章(九)本章测试

瀑布型项目管理最常用的10个小工具,可以自由搭建使用

How to become a senior digital IC Design Engineer (4-2) script: file read / write operation realized by Verilog HDL code

干货丨微服务架构是什么?有哪些优点和不足?

【Redis】List类型

Project R & D, what are the free brain mapping tools that are easy to use

【Redis】Hash类型

How to become a senior digital IC Design Engineer (4-3)

Introduction to openresty
随机推荐
[redis] set type
RISC CPU design based on FPGA (4) 36 questions about the project and their answers
哪个证券公司最大最安全 哪家券商服务好
To apply for a test engineer after years, the resume with high scores should be written like this
干货丨微服务架构是什么?有哪些优点和不足?
[learn FPGA programming from scratch -49]: Vision - how is the chip designed?
Google Borg论文
学习太极创客 — MQTT 第二章(九)本章测试
How to use project Gantt chart to make project report
Studies of relative costs for development in different languages
Which brokerage is safer and more convenient to open an account for compass mobile stock?
Trigonometric function calculation
MySQL详解 --- 聚合与分组
字符串替换
table通过伪类实现 另类自适应
数字 IC 设计、FPGA 设计秋招笔试题目、答案、解析(1)2022 紫光展锐(上)
[redis] key hierarchy
[redis] list type
利用kubernetes资源锁完成自己的HA应用
Temperature conversion II