search
Homephp教程php手册PHP中exec函数和shell_exec函数的区别,execshell_exec

PHP中exec函数和shell_exec函数的区别,execshell_exec

这两个函数都是执行Linux命令函数,不同的是获取返回结果不一样,exec只能获取最后一行数据,shell_execu则可以获取全部数据。

假如脚本路径下有如下文件:

复制代码 代码如下:


-bash-4.1# ll
总用量 12
-rw-rw-r--. 1 www web 133  7月 16 15:00 a.php
-rw-r--r--. 1 lee web  59  2月 29 17:05 b.php
-rw-r--r--. 1 lee web  81  3月  8 17:00 c.php


exec例子

复制代码 代码如下:


/**
 * exec与shell_exec的区别
 * 琼台博客
 */
$data = exec('/bin/ls -l');
echo '

';<br>
print_r($data);<br>
echo '
';
?>

执行结果

复制代码 代码如下:


-rw-r--r--. 1 lee web  81 Mar  8 17:00 c.php


shell_exec例子

复制代码 代码如下:


/**
 * exec与shell_exec的区别
 * 琼台博客
 */
$data = shell_exec('/bin/ls -l');
echo '

';<br>
print_r($data);<br>
echo '
';
?>

执行结果

复制代码 代码如下:


total 12
-rw-rw-r--. 1 www web 139 Jul 16  2012 a.php
-rw-r--r--. 1 lee web  59 Feb 29 17:05 b.php
-rw-r--r--. 1 lee web  81 Mar  8 17:00 c.php


所以平时使用exec函数的童鞋注意了,如果你需要获取全部返回信息,就应该使用shell_exec函数,当然,如果命令执行结果只有一行返回信息,那么使用哪个都无所谓。

linux 中php执行shell_exec函数

shell_exec("/usr/local/bin/pdf2swf /home/xiazai/03.pdf -o /home/xiazai/1.swf; /usr/local/bin/jpeg2swf /home/xiazai/2.jpg -o /home/xiazai/2.swf ");
每条命令后加上分号
 

PHPini开启EXEC函数怎开启

首先是 要关掉 安全模式 safe_mode = off

然后在看看 禁用函数列表
disable_functions = proc_open, popen, exec, system, shell_exec, passthru

这里要把 exec 去掉
重启 apache 就OK了
 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.