0

I am trying to create a tarball from a php5 script under Linux, and I don't really care for the output; the way I have so far found immediately is to simply

system("tar czf tarball.tgz directory/path &");

However I would like to background the process

Checking system() documentation it mentions having to redirect the output to file

However

system("tar czf tarball.tgz directory/path > /dev/null 2>&1");

doesn't help. The system() function does not take a file descriptor... what am I missing?

Testing with these:

script test.php

<pre><?php

exec("bash dodate 2>&1 /dev/null &");
system("echo done at \$(date)");

?></pre>

Script ./dodate

sleep 5
date

I go to my browser and call/refresh the page; it takes indeed 5 seconds thenprints/updates the "done" message.

Thanks

3
  • That & at the end of your first snippet should make it run in the background - does it not? Do you need to report the output/result to your PHP program, or can it just continue without knowing? Commented Jan 13, 2016 at 23:15
  • If you don't care about the output, exec() may be a better option for you: php.net/manual/en/function.exec.php Commented Jan 13, 2016 at 23:16
  • Alas, the ampersand does not background the process... specifically I tested this by creating a script "dodate" with contents sleep 5 ; date and then calling system("bash dodate &") but it waits and then prints the output...! Same effect with exec Commented Jan 13, 2016 at 23:18

1 Answer 1

0

You "don't have" threads in php. One trick you can do is to do a curl request to another php that does what you want. You'll need to make sure that your curl times out pretty soon, and that the other php doesn't die when the http connection to it is closed by the curl timeout.

You can also read about the topic here: cURL Multi Threading with PHP or cURL Multi Threading?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.