The difference between exec and system usage in PHP

Source: Internet
Author: User
Tags learn php learn php programming
This article mainly introduces the analysis of the difference between exec and system usage in PHP, which can help to understand the PHP program design, and the friends who need to refer to

In this paper, we describe the differences between exec and system usage in PHP, and share them for your reference. Here's how:

In general, calling external commands in PHP can be implemented using EXEC and system:

System ()


String system (String command [, int return_var])

The system () function is similar in other languages, it executes the given command, outputting and returning the result. The second parameter is optional and is used to get the status code after the command executes.

return Result:

Successfully returned 0,
Failure (Command not present, etc.) returns a value other than 0



String exec (String command [, string array [, int return_var]])

The exec () function, like system (), also executes the given command, but does not output the result, but instead returns the last line of the result. Although it returns only the last line of the command result, the second parameter array gives the complete result by appending the result line to the end of the array. So if the array is not empty, it is best to clear it with unset () before calling it. The third parameter can be used to obtain the status code of the command execution only if the second parameter is specified.

Examples of use are as follows:

I hope this article will be helpful for you to learn PHP programming.

  • Related Article

    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: 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.