Home  >  Article  >  Backend Development  >  How to execute shell in php without waiting for response

How to execute shell in php without waiting for response

藏色散人
藏色散人Original
2021-07-01 09:37:582560browse

How to execute shell without waiting for response in php: first open the corresponding background; then implement it through the "system("nohup ./test.py $s &");" method.

How to execute shell in php without waiting for response

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to execute shell without waiting for response?

How to use system to run commands in the background without waiting for the result

system("nohup ./test.py $s &");

This will not run in the background, and php will hang until the end of test.py.

system("nohup ./test.py $s >>log.txt &");

Write this way to run in the background. Because the system function starts a program and wants to keep it running in the background,

You must ensure that the output of the program is redirected to a file or other output stream. Otherwise PHP will hang before program execution ends.

For example:

1. system(“nohup ./test.py $s >>/tmp/output.txt &”);

2. system (“nohup ./test.py $s > /dev/null 2>&1 &”);

(2>&1 is the error output to the standard output. If you want to read the error output, add 2>&1 , no error can be read without adding)

Or system(“nohup ./test.py $s > /dev/null &”);

Recommended learning:《PHP video tutorial

The above is the detailed content of How to execute shell in php without waiting for response. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn