PHP exec () function introduction and use DEMO, execdemo

Source: Internet
Author: User

PHP exec () function introduction and use DEMO, execdemo

The exec () function is used to execute an external program. We can use this function in linux.

Enable the exec () function:

The exec () function is disabled. To use this function, you must enable it first. First, disable the security mode safe_mode = off. Then look at the disabled function list.
Disable_functions = proc_open, popen, exec, system, shell_exec, passthru
Remove exec and restart apache.

Basic usage of the exec () function:

Exec (string $ command [, array & $ output [, int & $ return_var]);

$ Command: indicates the command to be executed.

$ Output: If the output parameter is provided, the array is filled with the output of command execution, and each row is filled with an element in the array. The data in the array does not contain spaces at the end of the line, for example, \ n. Note that if the array already contains some elements, the exec () function will append content to the end of the array. If you do not want to append an array, use the unset () function to reset the array before passing in the exec () function.

$ Return_var: if both output and return_var parameters are provided, the return status after the command is executed is written to this variable.

In general, we only need to write the first parameter, that is, $ command.

Because the exec () function is mainly used to execute external programs, here we will take the linux system as an example to do a few demo Tutorials:

<?php$command "ls /tmp/test"// Ls is the directory for querying files in linux.exec($command,$array); // Execute the commandprint_r($array);?>

The returned results are as follows:

[root@krlcgcms01 shell]# php ./exec.phpArray([0] => 1001.log[1] => 10.log[2] => 10.tar.gz[3] => aaa.tar.gz[4] => mytest[5] => test1101[6] => test1102[7] => weblog_2010_09)

My blog address: Introduction to PHP exec () function and use DEMO http://www.wangtuizhijia.com/archives/131

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.