๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.system.php
PHP: system - Manual
You probably want to check your system calls for errors. The convention is to return 0 for "no error" which is the same as FALSE which can be confusing. You need to do something like: <?php $cmd = "/usr/bin/pngtopnm $png_file > $pnm_file"; system($cmd,$return_value); ($return_value == 0) or die("returned an error: $cmd"); ?>
๐ŸŒ
PHP: The Right Way
phptherightway.com
PHP: The Right Way | Reference for PHP best practices
An easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative PHP tutorials around the Web
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ php โ€บ php_system_calls.htm
PHP System Calls
passthru(string $command, int &$result_code = null): ?false <?php passthru ('PATH'); ?> ... PATH=C:\Python311\Scripts\;C:\Python311\;C:\WINDOWS\system32;C:\WINDOWS; C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\; C:\WINDOWS\System32\OpenSSH\;C:\xampp\php;C:\Users\mlath\AppData\Local \Microsoft\WindowsApps;C:\VSCode\Microsoft VS Code\bin
๐ŸŒ
BCCNsoft
doc.bccnsoft.com โ€บ docs โ€บ php-docs-7-en โ€บ function.system.html
Execute an external program and display the output
<?php echo '<pre>'; // Outputs all the result of shellcommand "ls", and returns // the last output line into $last_line. Stores the return value // of the shell command in $retval. $last_line = system('ls', $retval); // Printing additional info echo ' </pre> <hr />Last line of the output: ' .
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_ref_filesystem.asp
PHP Filesystem Functions
The behavior of the filesystem functions is affected by settings in php.ini. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ php-tutorial โ€บ php-file-system.php
Understanding PHP File System Functions - Tutorial Republic
In this tutorial you will learn how to create, access (or read) and manipulate files dynamically using the PHP's file system functions.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ php-tutorial
PHP Tutorial - GeeksforGeeks
August 13, 2025 - Install PHP in your Windows System | Linux | or MacOS
๐ŸŒ
Acunetix
acunetix.com โ€บ blog โ€บ articles โ€บ web-shells-101-using-php-introduction-web-shells-part-2
Web Shells 101 Using PHP (Web Shells Part 2) | Acunetix
March 5, 2025 - <?php // Return the listing of the directory where the file runs (Windows) system("dir"); ?> --> Volume in drive C has no label. Volume Serial Number is A08E-9C63 Directory of C:\webserver\www\demo 02/27/2020 10:21 PM <DIR> . 02/27/2020 10:21 PM <DIR> ..
Find elsewhere
Top answer
1 of 5
220

They have slightly different purposes.

  • exec() is for calling a system command, and perhaps dealing with the output yourself.
  • system() is for executing a system command and immediately displaying the output - presumably text.
  • passthru() is for executing a system command which you wish the raw return from - presumably something binary.

Regardless, I suggest you not use any of them. They all produce highly unportable code.

2 of 5
174

The previous answers seem all to be a little confusing or incomplete, so here is a table of the differences...

+----------------+-----------------+----------------+----------------+
|    Command     | Displays Output | Can Get Output | Gets Exit Code |
+----------------+-----------------+----------------+----------------+
| system()       | Yes (as text)   | Last line only | Yes            |
| passthru()     | Yes (raw)       | No             | Yes            |
| exec()         | No              | Yes (array)    | Yes            |
| shell_exec()   | No              | Yes (string)   | No             |
| backticks (``) | No              | Yes (string)   | No             |
+----------------+-----------------+----------------+----------------+
  • "Displays Output" means it streams the output to the browser (or command line output if running from a command line).
  • "Can Get Output" means you can get the output of the command and assign it to a PHP variable.
  • The "exit code" is a special value returned by the command (also called the "return status"). Zero usually means it was successful, other values are usually error codes.

Other misc things to be aware of:

  • The shell_exec() and the backticks operator do the same thing.
  • There are also proc_open() and popen() which allow you to interactively read/write streams with an executing command.
  • Add "2>&1" to the command string if you also want to capture/display error messages.
  • Use escapeshellcmd() to escape command arguments that may contain problem characters.
  • If passing an $output variable to exec() to store the output, if $output isn't empty, it will append the new output to it. So you may need to unset($output) first.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ creating-a-registration-and-login-system-with-php-and-mysql
Creating a Registration and Login System with PHP and MySQL - GeeksforGeeks
December 19, 2025 - Here we use HTML, CSS, Bootstrap, and JavaScript to create a responsive web application with a dynamic error-handling mechanism. PHP and MYSQL are used for server-side rendering and Database management.
๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ php โ€บ secure login system with php and mysql
Secure Login System with PHP and MySQL
May 26, 2025 - Ready to build a secure PHP login system from scratch? This beginner-friendly PHP login tutorial guides you step-by-step in creating a robust login form using PHP and MySQL.
๐ŸŒ
Learnosity
help.learnosity.com โ€บ hc โ€บ en-us โ€บ articles โ€บ 360000757757-Environment-Setup-Guide-PHP
Environment Setup Guide - PHP โ€“ Learnosity Product & Developer Help
This page contains instructions for setting up the PHP programming language runtimes for various operating systems. Learnosity can be used with any server-side language. Additionally, we have creat...
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ php โ€บ index.htm
PHP Tutorial
Similarly, Laravel is used in E-commerce platforms, Social networking apps, and CRM systems. ... To run a PHP application, you need a server, a database server, and a PHP parser software.
๐ŸŒ
W3Schools
w3schools.com โ€บ php
PHP Tutorial
<!DOCTYPE html> <html> <body> <?php echo 'My first PHP script!'; ?> </body> </html> Try it Yourself ยป ยท Click on the "Try it Yourself" button to see how it works. Most chapters in this tutorial end with exercises where you can check your knowledge.