Louis B.
Louis B.

Reputation: 2368

Using header(), does the header get sent instantly, or after the full script has run?

I'm working with an external service that polls data from my app. A requirement of this external service is that I have to let it know that its request was successful after a maximum of 10 seconds. The problem is that the script this service connects to might take more than 10 seconds to execute.

My question is: When I sent the headers via header('HTTP/1.0 200 OK', true, 200);, will the external service receive this response immediately, or only after my script has executed completely? Example:

header('HTTP/1.0 200 OK', true, 200);
some_function_that_takes_20_seconds()

Will the response header be sent immediately or only after 20 seconds?

Upvotes: 2

Views: 1467

Answers (2)

Robert
Robert

Reputation: 41

Not sure you have resolved your problem but try

ignore_user_abort(true);
set_time_limit(0);
header('HTTP/1.0 200 OK', true, 200);
flush();

Upvotes: 0

jgauld
jgauld

Reputation: 649

You can explicitly send the header by calling flush() immediately after your header() call, otherwise I believe no headers are sent until the output buffer is flushed, or your script finishes - whichever comes first.

Upvotes: 3

Related Questions