How to execute shell in php without waiting for response

藏色散人
Release: 2023-03-11 06:52:01
Original
2311 people have browsed it

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 &");
Copy after login

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

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

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!