PHP Function: Built-in Functions part 9

Program Execution Functions 
You can use PHP’s built in program execution functions to use programs residing on your system, such as encryption programs, third-party image manipulation programs, and so forth. For all program execution functions, the PHP user much have permission to execute the given program.

exec() 
The exec() function executes an external program. its syntax is

exec(command, [array], [return_var]);

If an array is specified, the output of the exec() function will append to the array. If return_var is specified, it will be assigned a value of the program’s return status.

For example, you would use the following  code to preform a “ping” of the server five times and return the output.

passthru() 
Like the exec() functions, the passthru() function executes an external program. The difference between the two is that the passthru() returns the raw output of the action. The syntax of passthru() is

passthru(command, return_var);

if return_var is specified, it will be assigned a value of the program’s return status.

system() 
The system() function executes an external program and displays output as the command is being executed. Its syntax is

system(command, [return_var]);

If return_var is specified it will be assigned a value of the programs’s return status.

For example, you would use the following code to ping a server 5 times and pring the raw output.

Next php function: Built-in Functions part 10