1

I have an Apache2.0/PHP web server setup on my development machine (windows) and on my test server (linux). There is one PHP script I have that runs a shell command to generate a PDF document. For example,

<?php

    //This script is kicked off via the browser,
    //ie. http://localhost/pdf.php

    exec('php generatePDF.php'); 
?>

The document can take up to several minutes to generate, although usually it completes in seconds.

On my Windows localhost, navigating away from this page while the script is executing will actually cause Apache to hang. On my Linux test server, this problem does not occur.

I have to expect that a user could navigate away from the page before the script has finished generating the document. Is this problematic for Apache?

Thanks, Brian

2
  • Why are you execing out to a php script, why not just call the script directly from your website?
    – Zypher
    Dec 17, 2009 at 22:29
  • I use exec so that I can run the script in the background if I need to (for other purposes) - this is a case where I cannot do that, suffice to say the document must be generated while the user waits.
    – Brian
    Dec 17, 2009 at 22:40

3 Answers 3

0

When a running script is interrupted (e.g. Esc is pressed) it's stopped, but only if set_timeout() condition occurs or any output function is called (like print). PDF generation will finish because it prints nothing while in progress :)

There should be no problem with such scripts, but you'd better move them offline so the connection won't take time, memory and connection slot (MaxConnections, remember? :)).

Apache hang during this process is very strange: sounds like a bug in Windows port of Apache. I've never met or heard of any issues like "never generate PDFs under Apache environment" :))

My only guess is there's pcntl_fork() used somewhere: this thing can really cause Apache hangs because it's multithreaded and PHP is a module: no fork()s should be made in such an environment.

0

You should really move the script offline if it takes that long. I don't know the specifics of what you are doing, but you probably want to just record what needs to be done, then run a cronjob to make it happen.

2
  • Fair enough - let's assume this is something that must be done while the user waits. Most of the time the script runs in under 5 seconds, and the problem is the same. I'm curious if something about this is bad for Apache, or if it's just something with my Windows configuration.
    – Brian
    Dec 17, 2009 at 22:49
  • Can you post sanitized apache error logs?
    – Zypher
    Dec 17, 2009 at 23:00
0

I guess the difference in behavior is cased by the fact that by default Win32 httpd is using thread-based worker, while on *nix-es httpd uses process-based worker by default.

When you say "causes Apache to hang" do you mean that httpd does not respond to any other requests? How long did you try to wait?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .