How to execute terminal command in background BY having command output to file?

180
January 19, 2020, at 08:10 AM

Command for merging files to one file.

$command = "
    nohup cd $video_dir;
     sleep 10; cat * > full-file.txt > /dev/null 2>&1 &";
exec( $command );

But php sleeps for 10 seconds. Need to have executing the command in background. The solution with /dev/null 2>&1 & doesn't work.

Answer 1

I have researched the solution. Command wrapping with parentheses solves the problem.

$command = "
     (cd $video_dir;
     sleep 10; cat * > full-file.txt) > /dev/null 2>&1 &";
exec( $command );
Rent Charter Buses Company
READ ALSO
Upgrading from PHP 5.6 to 7.4

Upgrading from PHP 5.6 to 7.4

Newbie hereI'm upgrading from PHP 5

156
PDO fetchALL command not returning data

PDO fetchALL command not returning data

I am trying to return information from my database, but all I get is an empty array when I know the database table is not empty

152
How to Get Both Proxy IP AND real remote IP into Nginx and PHP

How to Get Both Proxy IP AND real remote IP into Nginx and PHP

I am trying to get two IP addresses into the headers so I can read them via PHP the proxy/middleman IP and the real remote client IPIs there a way to get both? I want the real ip in "REMOTE_ADDR" and then the proxy IP in a custom header but it seems if i overwrite...

175
Move all LAMP to Node/Nginx/JS framework? [closed]

Move all LAMP to Node/Nginx/JS framework? [closed]

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post

164