7

I have a script named data.php that looks like this:

/* do some stuff */
echo $result;
/* do some other stuff (eg database operations) */

I need to use the output of data.php in another script but I don't want the caller script to wait until data.php is finished.

What's the easiest way to do this?

Thanks in advance!

2 Answers 2

8

Take a look at the flush() function: http://php.net/manual/en/function.flush.php

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

2 Comments

No webserver nor web browser involved here. Just passing data from script to script.
@Daniel flush works on the output stream regardless of context. It doesn't matter if this is a webserver or command-line.
2

Theoretically speaking (writing) one script should output to a stream, and the other should read from the same stream.
A good (and simple) example would be one file writes to a file on HD, the other reads from it. Simplest, but not the best.

2 Comments

Hmm, seems to be more complicated than I thought. Maybe I could also fork a child process for the remaining stuff...
NNNnnice, I'm totally doing that... ajax requests that just keep reading the output file. And instead of echo in the main php, we write to that output file... so clever...

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.