Câu hỏi phỏng vấn PHP
Câu hỏi

Explain the difference between exec() vs system() vs passthru() ?

Câu trả lời

In PHP, the exec(), system(), and passthru() functions are used to execute external programs, but they handle the output differently:

  1. exec():

    • Functionality: Executes the command and returns the last line of the output as a string.
    • Output Handling: Does not print the output directly; it can be captured and processed within the PHP script.
    • Return Value: Returns the last line of the command output or FALSE on error.
    • Example:
      php Copy
      $output = exec('ls -l');
      echo $output;
    • Use Case: Suitable when you need to capture and process the output programmatically.
  2. system():

    • Functionality: Executes the command and prints the output directly to the output buffer.
    • Output Handling: Prints each line of the output as it is generated.
    • Return Value: Returns the last line of the command output as a string or FALSE on error.
    • Example:
      php Copy
      system('ls -l');
    • Use Case: Useful when you want to display the output directly to the user or the browser.
  3. passthru():

    • Functionality: Executes the command and passes the raw output directly to the output buffer.
    • *Output Handling...
middle

middle

Gợi ý câu hỏi phỏng vấn

entry

What is the purpose of php.ini file?

junior

What do we mean by keys and values?

middle

What is the difference between MySQL, MySQLi and PDO?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào