when the PHP program runs on the Safe Mode next time, PHPScript are subject to the following four limitations:
1), execute external command
2), there are some limitations when opening a file
3), connect MySQL database
4), HTTP-based authentication
In Safe Mode , only external programs in a specific directory can be executed , and other programs
The call will be rejected. This directory can be used in the php.ini file with the Safe_mode_exec_dir Directive,
Or in compiling PHP is plus--with-exec-dir option
To specify that the default is/usr/local/php/bin.
If you call an external command that should be able to output results (meaning PHP scripts are error-free), get the
but it's a blank, so maybe PHP is running on Safe Mode the.
In this case, how to deal with it?
Calling external commands in PHP can be implemented in three ways:
PHP provides 3 specialized functions for executing external commands:
System (), exec (), PassThru ().
System ()
Prototype: 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, used to get the status code after the command is executed.
Example:
Copy Code The code is as follows:
System ("/usr/local/bin/webalizer/webalizer");
?>
EXEC ()
Prototype: 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,
The method is to append the result row by line to the end of the array. So if the array is not empty , the most useful before calling
unset () clear it off. the third parameter can be used to obtain the status code of the command execution only if the second parameter is specified.
Example:
Copy Code The code is as follows:
EXEC ("/bin/ls-l");
EXEC ("/bin/ls-l", $res);
# $res is a data, each element represents a row of results
EXEC ("/bin/ls-l", $res, $RC);
# The value of the $RC is the status code of the command/bin/ls-l. The case of success is usually 0
?>
PassThru ()
Prototype: void PassThru (String command [, int return_var])
PassThru () only invokes the command, does not return any results, but the command's run result is directly
output to Standard on the output device . so the PassThru () function is often used to call a pbmplus (Unix-like
a tool for dealing with pictures, The stream of the original picture that outputs the binary)
Such a program. It can also get the status code of the command execution.
Example:
Copy Code The code is as follows:
Header ("Content-type:image/gif");
PassThru ("./ppmtogif hunte.ppm");
?>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP call external Shell method summary 1, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.