how to trigger a background tar archive process on apache server
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to trigger a background tar archive process on apache server
I would like to trigger a background tar process on apache server by a client browser request for a page.
I tried to have a PHP script execute exec("tar.... command &", ...) on the server when it handle the page request from the client. The server trigger the tar command but instead of running it as a background process while it finish generating the page and return it to the browser, it wait untill the tar command is done.
How can I cause the server to run the tar in the backgound and return immediately to the user?
This relates to the relationship of a web server and it's child CGI process. As the parent process, the web server launches the CGI child process with the child's stdout directed to a file descriptor on the web server that is open for reading. The web server wants to swallow all of the output from the child process, so it waits for the file descriptor to reach eof(), which normally doesn't happen until the child process terminates. This is all consistent with the behavior you are reporting.
In order for the web server to see eof() on it's child's output, you will need to coerce the child process to close it's stdout stream. For most applications, this is not possible, since the application simply isn't written with that scenario in mind. The solution, then, is probably to launch an intermediate CGI that can launch the tar process, but can also close it's standard output, so the web server can return a page to the client browser, and stop waiting for the child to complete.
--- rod.
questions:
1. if I close the child process stdout will it not trigger the server to close/kill the child process? or does the server allow the child process to continue running even after its stdout is closed? keep in mind that the archive process which is the function of this child process may take a long time.
2. In my case the child process is a PHP script, if I close the PHP stdout will it be good enough?
I don't think there are any hard rules for this kind of thing. The specific web server will do whatever it sees fit. I think that an Apache web server will only look at the child process' standard output, and leave the child running. I'm not sure PHP is handled the same way as a CGI child, since PHP is, in some way, built into the web server, at east as I understand it. I've never really used PHP enough to know the behavior in this circumstance.
--- rod.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.