The difference between the EXEC function and the shell_exec function in PHP, execshell_exec_php tutorial

Source: Internet
Author: User

The difference between the EXEC function and the shell_exec function in PHP, execshell_exec


Both functions execute the Linux command function, except that the return result is not the same, exec can only get the last row of data, and SHELL_EXECU can get all the data.

If the script path has the following file:
Copy the Code code as follows:
-bash-4.1# LL
Total Dosage 12
-rw-rw-r--. 1 www web 133 July 15:00 a.php
-rw-r--r--. 1 Lee Web 59 February 17:05 b.php
-rw-r--r--. 1 Lee Web 81 March 8 17:00 c.php

exec Example
Copy the Code code as follows:
<?php
/**
* The difference between exec and shell_exec
* Jones Taiwan Blog
*/
$data = EXEC ('/bin/ls-l ');
Echo '

';
Print_r ($data);
Echo '
';
?>

Execution results
Copy CodeThe code is as follows:
-rw-r--r--. 1 Lee Web Bayi Mar 8 17:00 c.php

shell_exec Example
Copy CodeThe code is as follows:
<?php
/**
* The difference between exec and shell_exec
* Jones Taiwan Blog
*/
$data = shell_exec ('/bin/ls-l ');
Echo '
';
Print_r ($data);
Echo '
';
?>

Execution results
Copy CodeThe code is as follows:
Total 12
-rw-rw-r--. 1 www web 139 Jul a.php
-rw-r--r--. 1 Lee Web 17:05 b.php
-rw-r--r--. 1 Lee Web Bayi Mar 8 17:00 c.php

So the children's shoes usually use the EXEC function notice, if you need to get all the return information, you should use the Shell_exec function, of course, if the command execution results only one row return information, then it doesn't matter what to use.


PHP performs shell_exec functions in Linux

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 ");
Add a semicolon after each command

Phpini Open EXEC function how to open

The first thing to do is to turn off safe mode Safe_mode = Off

And then look at the list of disabled functions
Disable_functions = Proc_open, Popen, exec, System, shell_exec, PassThru

We're going to remove exec here.
Reboot Apache is OK.

http://www.bkjia.com/PHPjc/866665.html www.bkjia.com true http://www.bkjia.com/PHPjc/866665.html techarticle The difference between the EXEC function and the shell_exec function in PHP, execshell_exec These two functions are to execute the Linux command function, the difference is to get the return result is not the same, exec can only get the last line number ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.