Everyone knows that the methods of executing system commands in PHP are:
system() prints and returns the last line of shell results.
exec() does not output results and returns the last line of shell results. All results can be saved in a returned array.
passthru() only calls the command and outputs the command's running results directly to the standard output device as is.
These methods will wait for the command to be executed before continuing to execute subsequent programs
Without blocking, you can write the command output to a recycle bin file of the system, so that the program will not block
For example:
<code>shell_<span>exec</span>(<span>"/use/local/php/bin/php /www/t.php > /dev/null 2>&1 &"</span>);</code>
You may often see in shell: >/dev/null 2>&1
The result of the command can be defined in the form of %> The output
/dev/null represents an empty device file
Represents where to redirect, for example: echo “123” > /home/123.txt
1 represents stdout standard output, the system default value is 1, so ">/dev/null" is equivalent to "1>/dev/null"
2 represents stderr standard error
& means equal to, 2>&1, indicating that the output redirection of 2 is equivalent to 1
Then the sentence of the title of this article:
1>/dev/null first means that the standard output is redirected to an empty device file, that is, no information is output to the terminal. To put it bluntly, no information is displayed.
2>&1 Next, standard error output redirection is equivalent to standard output, because standard output has been redirected to an empty device file before, so standard error output is also redirected to an empty device file.
The above introduces the method of executing PHP shell without blocking, including shell content. I hope it will be helpful to friends who are interested in PHP tutorials.