1

I have a PHP script that needs to process some more information in the background after returning the response.

I made it work by following this answer as well as turning off FastCGI Output Buffer:

<IfModule mod_fcgid.c>
FcgidOutputBufferSize 0
</IfModule>

It won't work without turning off FastCGI Output Buffer.

However, I only have one script that needs this. It would be nice if I can keep FastCGI Output Buffer for all other scripts.

Is it possible to just make one PHP script ignore FastCGI Output Buffer?

5
  • 1
    It sounds like you need to run a task in the background, not futz around with output buffering. Commented Aug 18, 2016 at 0:59
  • But the user needs to initiate it with data. Commented Aug 18, 2016 at 1:11
  • 1
    Yeah so whatever function this is takes its parameters, performs its immediate tasks [eg: content generation], starts the background task, and returns. The page is delivered as expected without having to selectively disable output buffering, and whatever long-running thing you started is still going in the background. Commented Aug 18, 2016 at 1:16
  • Yes it's exactly what I need. Please add an answer with some code example. Like I said, the script I took from the other post's answer won't work without turning off FastCGI Output Buffer. The user gets the response after the long-running task finishes. Commented Aug 18, 2016 at 5:37
  • In that specific case, you could just prefill the (default) buffer, e.g. echo str_repeat(' ', 65537); Commented Jul 16, 2020 at 9:49

1 Answer 1

1

Maybe you can use nested Apache directives to check the request URI. Like this:

<IfModule mod_fcgid.c>
    <If "%{REQUEST_URI} == '/path/to/script.php'">
        FcgidOutputBufferSize 0
    </If>
</IfModule>
Sign up to request clarification or add additional context in comments.

4 Comments

What if I only need this for a specific function in the script?
@Shawn Sorry I don't know how to do that. Hopefully someone else who knows can answer.
cPanel keeps throwing me syntax error with your solution. Any idea?
@Shawn I'm not sure why there is a syntax error. I used this page as a reference: httpd.apache.org/docs/current/expr.html#examples. It looks like it should work. The error doesn't give you any more detail?

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.